[cpp-threads] Somewhat relevant technical report

Alexander Terekhov alexander.terekhov at gmail.com
Fri Dec 16 11:55:18 GMT 2005


On 12/15/05, Boehm, Hans <hans.boehm at hp.com> wrote:
> Report HPL-2005-217, "Reordering Constraints for Pthread-Style Locks",
> became available at
> http://www.hpl.hp.com/techreports/2005/HPL-2005-217.html .
>
> This basically asks and answers the question of what memory fences are
> required by pthread locks, if you try as much as possible to take the
> current spec at face value.  (Pthread_mutex_lock() requires a full
> barrier, pthread_mutex_unlock() doesn't.)

At face value, pthread_mutex_trylock() doesn't synchronize on failure and
I disagree that "example could easily be made Posix conforming by adding
a lock(l2); unlock(l2); immediately after the while loop, where l2 is otherwise
unused". Under my interpretation of (busted) XBD 4.10, example could
easily be made Posix conforming using pthread_barrier_t and
pthread_mutex_lock() doesn't require a full barrier.

initially: pthread_barrier_init(&b, 0, 1);

T1: v1 = 1; pthread_barrier_wait(&b); lock(l1);

T2: r1 = try_lock(l1);
while (r1) { unlock(l1); r1 = try_lock(l1); }
pthread_barrier_wait(&b);
r2 = v1; out(r2);

regards,
alexander.



More information about the cpp-threads mailing list