| Author |
Message |
< Erlang ~ semaphore (mutex) |
| vinnitu |
Posted: Fri Sep 10, 2010 2:50 pm |
|
|
|
User
Joined: 31 May 2007
Posts: 14
|
i found example of mutex in erlang
Can somebody modify it to use it with count like semaphore?
Thx
Code:
-module(mutex).
-export([start/0, stop/0]).
-export([wait/0, signal/0]).
-export([init/0]).
start() ->
register(mutex, spawn(?MODULE, init, [])).
stop() ->
mutex ! stop.
wait() ->
mutex ! {wait, self()},
receive ok -> ok end.
signal() ->
mutex ! {signal, self()},
ok.
init() ->
free().
free() ->
receive
{wait, Pid} ->
Pid ! ok,
busy(Pid);
stop ->
terminate()
end.
busy(Pid) ->
receive
{signal, Pid} ->
free()
end.
terminate() ->
receive
{wait, Pid} ->
exit(Pid, kill),
terminate()
after
0 -> ok
end. |
|
|
| Back to top |
|
| zajda |
Posted: Sat Sep 11, 2010 10:47 pm |
|
|
|
User
Joined: 22 Aug 2009
Posts: 83
|
|
| Back to top |
|
| jwatte |
Posted: Fri Sep 24, 2010 6:05 pm |
|
|
|
User
Joined: 10 Feb 2010
Posts: 34
|
vinnitu wrote: i found example of mutex in erlang
Writing a process that keeps a count as state is one of the very first Erlang tutorial examples. Adding a list of processes waiting for the semaphore is a minor addition.
However, I think the "Erlang way" is to use a process to "drive" whatever the resource is that you want to serialize, rather than to use a separate synchronization primitive. Or, if your semaphore is counting something like buffers, simply model the producer/consumer relationship directly as communicating processes. |
|
|
| Back to top |
|
| wojtnar |
Posted: Fri Oct 01, 2010 9:37 am |
|
|
|
Joined: 05 Feb 2010
Posts: 7
|
vinnitu wrote:
i found example of mutex in erlang
Can somebody modify it to use it with count like semaphore?
Is this for fun, work or rather homework?
--Wojtek |
|
|
| Back to top |
|
| wuji |
Posted: Tue Sep 04, 2012 7:32 am |
|
|
|
User
Joined: 10 Aug 2012
Posts: 654
|
all stay?'" Denniston said.The team agreed."I love swimming under Dave, Dave, replica designer *beep* Dave, and I think he is a good fit," said
Kamber, a member of the Paralympics swimming team. "He understands understands [h2]cheap jordans[/h2] understands each of our training needs."Recently, Denniston was announced as
head coach of the 2012 Paralympic Resident Swim team in in [h4]cheap polo shirts[/h4] in Colorado Springs -- the same position his mentor Flowers
before him.Denniston said that if he had to sum up up [h2]replica designer *beep*[/h2] up his experiences since his 2005 accident in a single |
|
|
| Back to top |
|
| dongdongwu |
Posted: Wed Sep 19, 2012 8:35 am |
|
|
|
User
Joined: 19 Sep 2012
Posts: 236
|
| Girls would refuse to even leave their replicas behind. specifically when the product beats the complete meaning of the Christian Louboutin men outlet; in conditions of good quality and detailing.If Cinderella was residing in your twenty primary century as opposed to the aged a single then there would not be any 'Happy actually after'. properly appears like girls nowadays are as well fond of the strong;Christian Louboutin Men Shoes to leave them in your center of nowhere.Christian Louboutin for men Shoes would arrive true handy being a excellent handbag using the glimpse and really feel belonging to the authentic but at a very much lesser price tag adding as very much as types picture in your process. |
|
|
| Back to top |
|
|
|