<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/lib/libpthread/thread/thr_mutex.c, branch releng/6.2</title>
<subtitle>FreeBSD source tree</subtitle>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/'/>
<entry>
<title>MFC: Relevent commit logs are below.</title>
<updated>2006-03-16T23:29:08+00:00</updated>
<author>
<name>Daniel Eischen</name>
<email>deischen@FreeBSD.org</email>
</author>
<published>2006-03-16T23:29:08+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=40837c5215e9e4c23b101a3189cd6c208d173e0c'/>
<id>40837c5215e9e4c23b101a3189cd6c208d173e0c</id>
<content type='text'>
  Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUG
  is defined in the environment.

  Modify the code path of the ifdef NOTYET part of _kse_single_thread():

  o  Don't reinitialise the atfork() handler list in the child.  We
     are meant to call the child handler, and on subsequent fork()s
     should call all three functions as normal.
  o  Don't reinitialise the thread specific keyed data in the
     child after a fork.  Applications may require this for context.
  o  Reinitialise curthread-&gt;tlflags after removing ourselves from
     (and reinitialising) the various internal thread lists.
  o  Reinitialise __malloc_lock in the child after fork() (to balance
     our explicitly taking the lock prior to the fork()).

  With these changes, it is possible to enable the NOTYET code in
  thr_kern.c to allow the use of non-async-safe functions after
  fork()ing from a threaded program.

  Eliminate a race condition in timed waits (cv, mutex, and sleeps).

  Don't forget to initialize a tailq before using it.

  For the ``#ifdef NOTYET'' code that allows calling non-async-safe
  functions in the child after a fork() from a threaded process,
  use __sys_setprocmask() rather than setprocmask() to keep our
  signal handling sane.  Without this fix, signals are essentially
  ignored in said child and things such as protection violations
  result in an endless busy loop.

  Allocate a thread's tcb last so it is easier to handle failures to
  malloc() siginfo.

  Include needed headers that were obtained through &lt;pthread.h&gt;.  Sort headers
  while here.

  amd64
  -----
  Fix a race condition introduced when redzones were added.  Use an
  atomic operation to return and adjust the stack (amd64).

  test
  -----
  o  Include &lt;string.h&gt;
  o  Make this ILP32/LP64 clean: cast pointers to long.

Approved by:	re (scottl)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
  Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUG
  is defined in the environment.

  Modify the code path of the ifdef NOTYET part of _kse_single_thread():

  o  Don't reinitialise the atfork() handler list in the child.  We
     are meant to call the child handler, and on subsequent fork()s
     should call all three functions as normal.
  o  Don't reinitialise the thread specific keyed data in the
     child after a fork.  Applications may require this for context.
  o  Reinitialise curthread-&gt;tlflags after removing ourselves from
     (and reinitialising) the various internal thread lists.
  o  Reinitialise __malloc_lock in the child after fork() (to balance
     our explicitly taking the lock prior to the fork()).

  With these changes, it is possible to enable the NOTYET code in
  thr_kern.c to allow the use of non-async-safe functions after
  fork()ing from a threaded program.

  Eliminate a race condition in timed waits (cv, mutex, and sleeps).

  Don't forget to initialize a tailq before using it.

  For the ``#ifdef NOTYET'' code that allows calling non-async-safe
  functions in the child after a fork() from a threaded process,
  use __sys_setprocmask() rather than setprocmask() to keep our
  signal handling sane.  Without this fix, signals are essentially
  ignored in said child and things such as protection violations
  result in an endless busy loop.

  Allocate a thread's tcb last so it is easier to handle failures to
  malloc() siginfo.

  Include needed headers that were obtained through &lt;pthread.h&gt;.  Sort headers
  while here.

  amd64
  -----
  Fix a race condition introduced when redzones were added.  Use an
  atomic operation to return and adjust the stack (amd64).

  test
  -----
  o  Include &lt;string.h&gt;
  o  Make this ILP32/LP64 clean: cast pointers to long.

Approved by:	re (scottl)
</pre>
</div>
</content>
</entry>
<entry>
<title>Use a generic way to back threads out of wait queues when handling</title>
<updated>2004-12-18T18:07:37+00:00</updated>
<author>
<name>Daniel Eischen</name>
<email>deischen@FreeBSD.org</email>
</author>
<published>2004-12-18T18:07:37+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=843d4004b367db61428fa1cbf611cdbd2791d672'/>
<id>843d4004b367db61428fa1cbf611cdbd2791d672</id>
<content type='text'>
signals instead of having more intricate knowledge of thread state
within signal handling.

Simplify signal code because of above (by David Xu).

Use macros for libpthread usage of pthread_cleanup_push() and
pthread_cleanup_pop().  This removes some instances of malloc()
and free() from the semaphore and pthread_once() implementations.

When single threaded and forking(), make sure that the current
thread's signal mask is inherited by the forked thread.

Use private mutexes for libc and libpthread.  Signals are
deferred while threads hold private mutexes.  This fix also
breaks www/linuxpluginwrapper; a patch that fixes it is at
http://people.freebsd.org/~deischen/kse/linuxpluginwrapper.diff

Fix race condition in condition variables where handling a
signal (pthread_kill() or kill()) may not see a wakeup
(pthread_cond_signal() or pthread_cond_broadcast()).

In collaboration with:	davidxu
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
signals instead of having more intricate knowledge of thread state
within signal handling.

Simplify signal code because of above (by David Xu).

Use macros for libpthread usage of pthread_cleanup_push() and
pthread_cleanup_pop().  This removes some instances of malloc()
and free() from the semaphore and pthread_once() implementations.

When single threaded and forking(), make sure that the current
thread's signal mask is inherited by the forked thread.

Use private mutexes for libc and libpthread.  Signals are
deferred while threads hold private mutexes.  This fix also
breaks www/linuxpluginwrapper; a patch that fixes it is at
http://people.freebsd.org/~deischen/kse/linuxpluginwrapper.diff

Fix race condition in condition variables where handling a
signal (pthread_kill() or kill()) may not see a wakeup
(pthread_cond_signal() or pthread_cond_broadcast()).

In collaboration with:	davidxu
</pre>
</div>
</content>
</entry>
<entry>
<title>Make pthread_mutex_trylock(3) return EBUSY on failure, as all software</title>
<updated>2004-10-31T05:03:50+00:00</updated>
<author>
<name>Brian Feldman</name>
<email>green@FreeBSD.org</email>
</author>
<published>2004-10-31T05:03:50+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=64926afd5038cae955429ac11bbfca9b3970c83b'/>
<id>64926afd5038cae955429ac11bbfca9b3970c83b</id>
<content type='text'>
packages expect and seems to be most correct according to the slightly-
ambiguous standards.

MFC after:		1 month
Corroborated by:	POSIX &lt;http://tinyurl.com/4uvub&gt;
Reviewed by: 		silence on threads@
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
packages expect and seems to be most correct according to the slightly-
ambiguous standards.

MFC after:		1 month
Corroborated by:	POSIX &lt;http://tinyurl.com/4uvub&gt;
Reviewed by: 		silence on threads@
</pre>
</div>
</content>
</entry>
<entry>
<title>Return EPERM if mutex owner is not current thread but it tries to</title>
<updated>2004-01-17T03:09:57+00:00</updated>
<author>
<name>David Xu</name>
<email>davidxu@FreeBSD.org</email>
</author>
<published>2004-01-17T03:09:57+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=e4dcaa6ee9fd1328b682b693d8aee2920f1ef96e'/>
<id>e4dcaa6ee9fd1328b682b693d8aee2920f1ef96e</id>
<content type='text'>
unlock the mutex, old code confuses some programs when it returns EINVAL.

Noticed by: bland
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
unlock the mutex, old code confuses some programs when it returns EINVAL.

Noticed by: bland
</pre>
</div>
</content>
</entry>
<entry>
<title>More reliably check timeout for pthread_mutex_timedlock.</title>
<updated>2003-12-09T00:52:28+00:00</updated>
<author>
<name>David Xu</name>
<email>davidxu@FreeBSD.org</email>
</author>
<published>2003-12-09T00:52:28+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=d5c854e8904326307d204ab210800f57e609e200'/>
<id>d5c854e8904326307d204ab210800f57e609e200</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add the ability to reinitialize a mutex (internally, not a userland</title>
<updated>2003-11-04T19:53:32+00:00</updated>
<author>
<name>Daniel Eischen</name>
<email>deischen@FreeBSD.org</email>
</author>
<published>2003-11-04T19:53:32+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=ee574ccc3ea9119e8c85602b930c9d3178cbb2d7'/>
<id>ee574ccc3ea9119e8c85602b930c9d3178cbb2d7</id>
<content type='text'>
API).

Reviewed by:	davidxu
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
API).

Reviewed by:	davidxu
</pre>
</div>
</content>
</entry>
<entry>
<title>As comments in _mutex_lock_backout state, only current thread</title>
<updated>2003-09-24T12:52:57+00:00</updated>
<author>
<name>David Xu</name>
<email>davidxu@FreeBSD.org</email>
</author>
<published>2003-09-24T12:52:57+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=3d10572d1a23b4302a0b0d0f9f57ab5eb788119a'/>
<id>3d10572d1a23b4302a0b0d0f9f57ab5eb788119a</id>
<content type='text'>
can clear the pointer to mutex, not the thread doing mutex
handoff. Because _mutex_lock_backout does not hold scheduler
lock while testing THR_FLAGS_IN_SYNCQ and then reading mutex
pointer, it is possible mutex owner begin to unlock and
handoff the mutex to the current thread, and mutex pointer
will be cleared to NULL before current thread reading it, so
current thread will end up with deferencing a NULL pointer,
Fix the race by making mutex waiters to clear their mutex pointers.
While I am here, also save inherited priority in mutex for
PTHREAD_PRIO_INERIT mutex in mutex_trylock_common just like what
we did in mutex_lock_common.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
can clear the pointer to mutex, not the thread doing mutex
handoff. Because _mutex_lock_backout does not hold scheduler
lock while testing THR_FLAGS_IN_SYNCQ and then reading mutex
pointer, it is possible mutex owner begin to unlock and
handoff the mutex to the current thread, and mutex pointer
will be cleared to NULL before current thread reading it, so
current thread will end up with deferencing a NULL pointer,
Fix the race by making mutex waiters to clear their mutex pointers.
While I am here, also save inherited priority in mutex for
PTHREAD_PRIO_INERIT mutex in mutex_trylock_common just like what
we did in mutex_lock_common.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add code to support barrier synchronous object and implement</title>
<updated>2003-09-04T14:06:43+00:00</updated>
<author>
<name>David Xu</name>
<email>davidxu@FreeBSD.org</email>
</author>
<published>2003-09-04T14:06:43+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=2ab83179b5b31c53a1b76ff437e1d075d64a3a95'/>
<id>2ab83179b5b31c53a1b76ff437e1d075d64a3a95</id>
<content type='text'>
pthread_mutex_timedlock().

Reviewed by: deischen
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
pthread_mutex_timedlock().

Reviewed by: deischen
</pre>
</div>
</content>
</entry>
<entry>
<title>Don't forget to unlock the scheduler lock.  Somehow this got removed</title>
<updated>2003-07-30T13:28:05+00:00</updated>
<author>
<name>Daniel Eischen</name>
<email>deischen@FreeBSD.org</email>
</author>
<published>2003-07-30T13:28:05+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=24dc93d4c203806ea5969bcd350aeec9df53a60b'/>
<id>24dc93d4c203806ea5969bcd350aeec9df53a60b</id>
<content type='text'>
from one of my last commits.  This only affected priority ceiling
mutexes.

Pointy hat to:	deischen
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
from one of my last commits.  This only affected priority ceiling
mutexes.

Pointy hat to:	deischen
</pre>
</div>
</content>
</entry>
<entry>
<title>Move idle kse wakeup to outside of regions where locks are held.</title>
<updated>2003-07-23T02:11:07+00:00</updated>
<author>
<name>Daniel Eischen</name>
<email>deischen@FreeBSD.org</email>
</author>
<published>2003-07-23T02:11:07+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=cc24e836059e12193a1dfb766c7ba78fcd905875'/>
<id>cc24e836059e12193a1dfb766c7ba78fcd905875</id>
<content type='text'>
This eliminates ping-ponging of locks, where the idle KSE wakes
up only to find the lock it needs is being held.  This gives
little or no gain to M:N mode but greatly speeds up 1:1 mode.

Reviewed &amp; Tested by:	davidxu
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This eliminates ping-ponging of locks, where the idle KSE wakes
up only to find the lock it needs is being held.  This gives
little or no gain to M:N mode but greatly speeds up 1:1 mode.

Reviewed &amp; Tested by:	davidxu
</pre>
</div>
</content>
</entry>
</feed>
