Advertisement
przemko

Współbieżność -- ciąg Fibonacciego

Jun 14th, 2017
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.30 KB | None | 0 0
  1. %% fib2.erl
  2.  
  3. -module(fib2).
  4. -export([fib/1]).
  5.  
  6. fib(0) -> 0;
  7. fib(1) -> 1;
  8. fib(N) ->
  9.     fib2(N - 1) + fib(N - 2).
  10.  
  11. fib2(N) ->
  12.     Pid = spawn(fun worker/0),
  13.     Pid ! {self(), N},
  14.     receive
  15.         F -> F
  16.     end.
  17.  
  18. worker() ->
  19.     receive
  20.         {From, N} -> From ! fib(N)
  21.     end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement