OSDN Git Service

fix deadlock race in pthread_once
authorRich Felker <dalias@aerifal.cx>
Wed, 16 Apr 2014 00:42:39 +0000 (20:42 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 16 Apr 2014 00:42:39 +0000 (20:42 -0400)
commit0d0c2f40344640a2a6942dda156509593f51db5d
treebaf15b9f4105f040e47e10b9bdaa56ad8e7c7fc5
parentfcea534e579077e10456f6ed06c033dfaa013a24
fix deadlock race in pthread_once

at the end of successful pthread_once, there was a race window during
which another thread calling pthread_once would momentarily change the
state back from 2 (finished) to 1 (in-progress). in this case, the
status was immediately changed back, but with no wake call, meaning
that waiters which arrived during this short window could block
forever. there are two possible fixes. one would be adding the wake to
the code path where it was missing. but it's better just to avoid
reverting the status at all, by using compare-and-swap instead of
swap.
src/thread/pthread_once.c