[erlang-questions] Semaphores

Robert Virding robert.virding@REDACTED
Thu Mar 15 23:28:35 CET 2007


Just some trivia. In the original Erlang book (not Joe's new one) there 
was a program example of an implementation of semaphores using message 
passing. The example was removed because it did not seem very useful to 
implement a basic feature using a more general one.

I don't think you actually need to receive and keep a list of 'P' 
processes. It should work if you just don't receive them until the 
process which has the semaphore releases it, does a 'V'. Then receive 
the next 'P' and wait until it releases the semaphore.

By adding processes to the list the way you do it, prepending them, 
means that they will be processed in the reverse order to which they 
seize the semaphore. This doesn't seem fair.

Robert

Danesh Daroui wrote:
> Hi all,
> 
> I have seen (even posts in this mailing list) that there is a need to 
> have Semaphores in Erlang and since Erlang offers concurrency, 
> Semaphores can be useful in data sharing. I have implemented a method 
> which enhances Erlang to support Semaphores. I am not sure if someone 
> else has done something like this before, but anyway, this is my 
> version. :)
> 
> I would be glad to have your feedbacks.
> 
> Cheers,
> 
> Danesh
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list