The Erlang Concurrency Model (L22) Flashcards

1
Q

Traditionally, each thread is treated as a single entity along with the other threads of the same program.

A

False - traditionally treated as separate entities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Treating each thread as a separate entity scales nicely, as the OS has full control.

A

False - too many threads leads to slices of allocated time that are too small.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The Erlang virtual machine creates its own super-lightweight threads. What are the pros to this?

A

A massive number of threads may be created with almost no resource overhead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The Erlang virtual machine creates its own super-lightweight threads. What are the cons to this?

A

All threads must share the same block of CPU time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many functions does Erlang provide for creating tasks and communicating between them? What are they?

A

3 - spawn, send, receive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What name is given to Erlangs lightweight threads?

A

Processes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the spawn function return?

A

The process ID of the new process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Give an example of using the spawn function to create a process.

A

Pid = spawn(module, func, args).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Child processes may execute prior to the parent process that created them.

A

True - there is no guarantee.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Concurrent Erlang application logic may depend on a rigid send/receive order.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What do X & Y represent in the below send function call?
X ! Y

A

X is the process ID of the target process, ! is the send operator, Y is the message (one or more data items).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Receive blocks are always written within the listen() function.

A

False - “find” is an arbitrary function name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What data structures can the following receive block accept?
listen() ->
receive
{dog, Name} ->
“Mr” ++ Name;
{cat, Name} ->
“Ms” ++ Name
end.

A

Tuples that either begin with the dog or cat atom (and which have 1 other element).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Receive blocks are terminated by what keyword?

A

end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Receive blocks execute for all messages in the queue that match one of its patterns.

A

False, the listen function terminates after the first match.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Messages that don’t match any pattern of the receive block are deleted.

A

False - they go into a “save” queue that may be checked again at a later time.

17
Q

Receive functions may only be invoked periodically.

A

False - they may be invoked continously.

18
Q

What type of application continuously invokes receive operations?

A

Server applications (web or dbms server)

19
Q

How are receive blocks continuously invoked if Erlang has limited support for iteration?

A

Using recursion: the receive block calls its own wrapper function.

20
Q

How does a process obtain its own process ID for two way communication?

A

Using self().

21
Q

Receive blocks may be nested.

A

True.

22
Q

Implement a timeout option (2000 milliseconds) into the following receive block:
receive
{Msg} -> do_something(Msg)
end.

A

receive
{Msg} -> do_something(Msg)
after 2000 -> do_something()
end.

23
Q

What does Erlang’s name registration service do?

A

Allows a process ID to be associated with a name/label.

24
Q

Using Erlang’s name registration service, processes can obtain the ID of all known/unknown concurrent process.

A

False - not if the name of the other process isn’t known.

25
Q

What function registers a process name with a process ID?

A

register(atomName, ID)

26
Q

What function removes a process name from the name registration service?

A

unregister (atomName)

27
Q

What does the following return?
whereis(atomName)

A

Returns the PID of atomName, or undefined if not found.

28
Q

What does the following return?
registered()

A

A list of all currently registered processes.

29
Q

It is possible to link processes together so that “supervisor” processes can be notified if a monitored process terminates.

A

True.

30
Q

Use a guard on the following receive pattern so that matching is conditional:
receive {Flag, Name} -> (…)

A

receive {Flag, Name} [when Flag == 1] -> (…)