The Erlang Concurrency Model (L22) Flashcards
Traditionally, each thread is treated as a single entity along with the other threads of the same program.
False - traditionally treated as separate entities.
Treating each thread as a separate entity scales nicely, as the OS has full control.
False - too many threads leads to slices of allocated time that are too small.
The Erlang virtual machine creates its own super-lightweight threads. What are the pros to this?
A massive number of threads may be created with almost no resource overhead.
The Erlang virtual machine creates its own super-lightweight threads. What are the cons to this?
All threads must share the same block of CPU time.
How many functions does Erlang provide for creating tasks and communicating between them? What are they?
3 - spawn, send, receive.
What name is given to Erlangs lightweight threads?
Processes.
What does the spawn function return?
The process ID of the new process.
Give an example of using the spawn function to create a process.
Pid = spawn(module, func, args).
Child processes may execute prior to the parent process that created them.
True - there is no guarantee.
Concurrent Erlang application logic may depend on a rigid send/receive order.
False.
What do X & Y represent in the below send function call?
X ! Y
X is the process ID of the target process, ! is the send operator, Y is the message (one or more data items).
Receive blocks are always written within the listen() function.
False - “find” is an arbitrary function name.
What data structures can the following receive block accept?
listen() ->
receive
{dog, Name} ->
“Mr” ++ Name;
{cat, Name} ->
“Ms” ++ Name
end.
Tuples that either begin with the dog or cat atom (and which have 1 other element).
Receive blocks are terminated by what keyword?
end.
Receive blocks execute for all messages in the queue that match one of its patterns.
False, the listen function terminates after the first match.