[concurrency-interest] park and unpark low-level details

Andrew Haley aph at redhat.com
Fri Nov 20 12:46:52 EST 2009


Something I've been wondering about.

In "The java.util.concurrent Synchronizer Framework" Doug writes:

<< This simple mechanism is similar to those used, at some level, in
the Solaris-9 thread library [11], in WIN32 "consumable events", and
in the Linux NPTL thread library, and so maps efficiently to each of
these on the most common platforms Java runs on.  (However, the
current Sun Hotspot JVM reference implementation on Solaris and Linux
actually uses a pthread condvar in order to fit into the existing
runtime design.) >>

What do you man by this?  I guess there's a nice way to map park and
unpark onto low-level NPTL primitives (futexes, perhaps?)  Did you
have a sketch of a design for that?

It probably doesn't much matter, given that pthread mutex and conndvar
signal a fairly thin wrappers over futexes, but unparking a blocked
thread requires three pthread_ calls:

     int status = pthread_mutex_lock(_mutex);

     AnyWaiters = _nParked ;

     status = pthread_mutex_unlock(_mutex);

     if (AnyWaiters != 0) {
        status = pthread_cond_signal(_cond);
     }

(I realize that the mutex is necessary to prevent a race when signalling
a thread that's parking.  I just wondered if you'd had another design in
mind.)

Thanks,
Andrew.


More information about the Concurrency-interest mailing list