NIF:
NIFs were introduced in Erlang/OTP R13B03 as an experimental feature. It is a simpler and more efficient way of calling C-code than using port drivers. NIFs are most suitable for synchronous functions, such as foo and bar in the example, that do some relatively short calculations without side effects and return the result.
- NIF disadvantage
NIF 可能导致整个VM 挂起 (NIF 中死循环)
process message passing
http://erlang.org/doc/getting_started/conc_prog.html#id68718
Each process has its own input queue for messages it receives. New messages received are put at the end of the queue. When a process executes a receive, the first message in the queue is matched against the first pattern in the receive. If this matches, the message is removed from the queue and the actions corresponding to the pattern are executed.
However, if the first pattern does not match, the second pattern is tested. If this matches, the message is removed from the queue and the actions corresponding to the second pattern are executed. If the second pattern does not match, the third is tried and so on until there are no more patterns to test. If there are no more patterns to test, the first message is kept in the queue and the second message is tried instead. If this matches any pattern, the appropriate actions are executed and the second message is removed from the queue (keeping the first message and any other messages in the queue). If the second message does not match, the third message is tried, and so on, until the end of the queue is reached. If the end of the queue is reached, the process blocks (stops execution) and waits until a new message is received and this procedure is repeated.
If there are no more patterns to test, the first message is kept in the queue and the second message is tried instead.
no need save queue.
NIF:
http://erlang.org/doc/tutorial/nif.html
NIF 可能导致整个VM 挂起 (NIF 中死循环)
process message passing
http://erlang.org/doc/getting_started/conc_prog.html#id68718
If there are no more patterns to test, the first message is kept in the queue and the second message is tried instead.
no need save queue.