[erlang-questions] Semaphores

ok ok@REDACTED
Fri Mar 16 06:13:25 CET 2007


On 16 Mar 2007, at 1:14 am, Danesh Daroui wrote:
> Frankly, the terms "p" and "v" are very famous, however it can be a  
> little confusing because as you mentioned they are Dutch acronyms  
> but semaphores are known by them now. So I think it is ok to still  
> use them. But I agree, as you said "acquire" and "release" are more  
> clear as Java used.


"p" and "v" are indeed famous.  But it is telling that NONE of the  
programming
languages or libraries I have ever used calls or called them that.   
To quote the
Wikipedia "semaphore" entry:
	In English textbooks, and in the programming language ALGOL 68, the  
P and V
	operations are sometimes called, respectively, down and up.  In  
software
	engineering practice they are called wait and signal, or take and  
release,
	or pend and post.
For example, the POSIX names are
	sem_post(2)	- unlock a semaphore
	sem_wait(2)	- lock a semaphore, waiting until this can be done
	sem_trywait(2)	- lock a semaphore if possible otherwise fail at once
POSIX avoided "signal" for fear of confusion with the signal() function.

I have known about "p" and "v" since, oh, 1975?  I have *never* been  
able to remember
which is which.

>> Oh yes, lists:append([PID], WaitList)
>> can be written more clearly as
>> 	[PID] ++ WaitList
>> and more clearly still as
>> 	[PID | WaitList].
>>
>>
>>
> It was a great tip. I was looking for a shortcut to add an element  
> to the list (like Haskell does) but I didn't find. But it is great  
> your wrote. Thanks again.

I'm not quite sure what you mean here.

	Haskell			Erlang
	[]			[]
	[1,2,3,4,5]		[1,2,3,4,5]
	(x : xs)		[X | Xs]
	xs ++ ys		Xs ++ Ys
	append xs ys		lists:append(Xs, Ys)

I think you'll find Joe's new book very helpful.







More information about the erlang-questions mailing list