On 5/12/2013 6:52 AM, egon wrote:
> I'm trying to implement a counting semaphore and in the "runtime" package
> there are semacquire and semrelease that could be used to implement it. I'm
> trying to figure why aren't they visible
Go should have P and V. Bounded buffers are built from P and V.
A bounded buffer is two P/V items and a circular buffer.
With an efficient implementation of P and V, you can implement all the
other locking primitives efficiently. Implementing P and V from
channels is backwards.
Dijkstra got this right back in 1974. Then the UNIX people screwed
up the locking primitives in UNIX, and we now have two or three
generations of programmers who know only the badly chosen primitives
kludged onto UNIX over the years.
Go has this mostly right. You want a basic mutex, P and V, and
bounded buffers. Anything else can be built on those. For
example, "WaitGroup". "Add" adds to a counter N, "Done" does a V,
and "Wait" does a P operation N times.
John Nagle