From a82e6c0f6dea14e07f726c4fb643459eecac6610 Mon Sep 17 00:00:00 2001 From: rstone Date: Fri, 11 Nov 2011 02:10:24 +0000 Subject: [PATCH] MFC 220888 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(). git-svn-id: svn://svn.freebsd.org/base/stable/8@227438 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libthr/thread/thr_once.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libthr/thread/thr_once.c b/lib/libthr/thread/thr_once.c index eb0706642..4f7037416 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) -- 2.45.0