This is the mail archive of the
mailing list for the GCC project.
Re: Patch for PR libgomp/37938, IA64 specific.
On Thu, Nov 06, 2008 at 04:00:12PM -0800, H.J. Lu wrote:
> Will this work
> static inline void gomp_mutex_unlock (gomp_mutex_t *mutex)
> int val = *mutex;
> __sync_lock_release (mutx);
> if (__builtin_expect (val > 1, 0))
> gomp_mutex_unlock_slow (mutex);
No, that's not atomic. Consider if this task reads 1 from *mutex
and sleeps in between the read and __sync_lock_release.
Another task in the mean time calls gomp_mutex_lock, which atomically
replaces 1 with 2 in memory and then calls gomp_mutex_lock_slow
and futex_wait in there. Then the first task wakes up, __sync_lock_release
releases the mutex, but as val is 1, doesn't futex_wake it. The
second task might wait forever.