[concurrency-interest] JSR 166 draft API

Paul Haahr paul@paulhaahr.com
Fri, 30 Aug 2002 00:08:19 -0700 (PDT)

Doug Lea wrote, replying to and quoting Mario Juric:
> > I think its a shame that non-reentrant mutexes are excluded from the first
> > release, because I really use them in a case where the lock is not released
> > by the same thread that has acquired it.
> Sorry for our lack of good documentation about this.

It is mentioned in the Semaphore description, which raised my hackles.

> A Semaphore initialized to 1 is precisely what you want in this case.
> Which of course will be supplied.

Actually, a semaphore initialized to 1 feels much heavier weight than a
simple non-reentrant mutex and easier to misuse.  (For example, a mutex
which is released twice can throw an exception, but I wouldn't expect
that from a semaphore.)

In this case, having two separate classes seems like it would reduce the
conceptual complexity of the APIs.

Consider me biased, however:  I never met a semaphore I liked.  They've
always seemed an obfuscating construct.