Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Created July 30, 2011 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostlygeek/1115965 to your computer and use it in GitHub Desktop.
Save mostlygeek/1115965 to your computer and use it in GitHub Desktop.
Programming Erlang 8.11 Problem #1
%% Write a function start(AnAtom, Fun) to register
%% AnAtom as spawn(Fun). Make sure your program
%% works correctly in the case when two parallel
%% processes simultaneously evaluate start/2. In
%% this case, you must guarantee that one of
%% these processes succeeds and the other fails.
-module(ch8prob1).
-export([start/2]).
start(AnAtom, Fun) ->
try register(AnAtom, spawn(Fun)) of
true -> true
catch
error:X -> {error, X}
end.
@mostlygeek
Copy link
Author

This is my solution for Programming Erlang Chapter 8, problem #1. It assumes that register/2 is guaranteed atomic within the system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment