Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Apr 2011 14:19:34 +0000 (UTC)
From:      Ryan Stone <rstone@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r220888 - head/lib/libthr/thread
Message-ID:  <201104201419.p3KEJYC4051900@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rstone
Date: Wed Apr 20 14:19:34 2011
New Revision: 220888
URL: http://svn.freebsd.org/changeset/base/220888

Log:
  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

Modified:
  head/lib/libthr/thread/thr_once.c

Modified: head/lib/libthr/thread/thr_once.c
==============================================================================
--- head/lib/libthr/thread/thr_once.c	Wed Apr 20 14:16:22 2011	(r220887)
+++ head/lib/libthr/thread/thr_once.c	Wed Apr 20 14:19:34 2011	(r220888)
@@ -64,6 +64,8 @@ _pthread_once(pthread_once_t *once_contr
 	struct pthread *curthread;
 	int state;
 
+	_thr_check_init();
+
 	for (;;) {
 		state = once_control->state;
 		if (state == ONCE_DONE)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104201419.p3KEJYC4051900>