diff options
author | rstone <rstone@FreeBSD.org> | 2011-04-20 14:19:34 +0000 |
---|---|---|
committer | rstone <rstone@FreeBSD.org> | 2011-04-20 14:19:34 +0000 |
commit | 488ea46b7d7c71796ada53fa9457888744b9ee6d (patch) | |
tree | 4ada84d5c8d0de23e04b6a39d2b43f9b5dcf345a /lib/libthr/thread | |
parent | 738b0a175176f8de0bd0fce5baa1460e18c1708a (diff) | |
download | FreeBSD-src-488ea46b7d7c71796ada53fa9457888744b9ee6d.zip FreeBSD-src-488ea46b7d7c71796ada53fa9457888744b9ee6d.tar.gz |
r179417 introduced a bug into pthread_once(). Previously pthread_once()
used a global pthread_mutex_t for synchronization. r179417 replaced that
with an implementation that directly used atomic instructions and thr_*
syscalls to synchronize callers to pthread_once. However, calling
pthread_mutex_lock on the global mutex implicitly ensured that
_thr_check_init() had been called but with r179417 this was no longer
guaranteed. This meant that if you were unlucky enough to have your first
call into libthr be a call to pthread_once(), you would segfault when
trying to access the pointer returned by _get_curthread().
The fix is to explicitly call _thr_check_init() from pthread_once().
Reviewed by: davidxu
Approved by: emaste (mentor)
MFC after: 1 week
Diffstat (limited to 'lib/libthr/thread')
-rw-r--r-- | lib/libthr/thread/thr_once.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_once.c b/lib/libthr/thread/thr_once.c index eb07066..4f70374 100644 --- a/lib/libthr/thread/thr_once.c +++ b/lib/libthr/thread/thr_once.c @@ -64,6 +64,8 @@ _pthread_once(pthread_once_t *once_control, void (*init_routine) (void)) struct pthread *curthread; int state; + _thr_check_init(); + for (;;) { state = once_control->state; if (state == ONCE_DONE) |