<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/lib/libthr/thread/thr_exit.c, branch release/5.3.0_cvs</title>
<subtitle>FreeBSD source tree</subtitle>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/'/>
<entry>
<title>This commit was manufactured by cvs2svn to create tag</title>
<updated>2004-11-04T19:12:42+00:00</updated>
<author>
<name>cvs2svn</name>
<email>cvs2svn@FreeBSD.org</email>
</author>
<published>2004-11-04T19:12:42+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=3f86d8a2ea3f3265afaa1fd263b0004c5c000e69'/>
<id>3f86d8a2ea3f3265afaa1fd263b0004c5c000e69</id>
<content type='text'>
'RELENG_5_3_0_RELEASE'.

This commit was manufactured to restore the state of the 5.3-RELEASE image.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
'RELENG_5_3_0_RELEASE'.

This commit was manufactured to restore the state of the 5.3-RELEASE image.
</pre>
</div>
</content>
</entry>
<entry>
<title>MFC:</title>
<updated>2004-10-09T15:12:33+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2004-10-09T15:12:33+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=101596b827d3570cefefd0b8a26a0e2e5cb7c23f'/>
<id>101596b827d3570cefefd0b8a26a0e2e5cb7c23f</id>
<content type='text'>
----------------------------
revision 1.15
date: 2004/10/08 14:48:02;  author: mtm;  state: Exp;  lines: +1 -4
Remove a reference to a non-existent syscall: _thr_exit(). The
actual name is thr_exit(). How this ever worked is beyond me.
----------------------------
revision 1.14
date: 2004/10/06 14:20:57;  author: mtm;  state: Exp;  lines: +2 -3
Close a race between a thread exiting and the freeing of it's stack.
After some discussion the best option seems to be to signal the thread's
death from within the kernel. This requires that thr_exit() take an
argument.

Discussed with: davidxu, deischen, marcel
MFC after: 3 days
=============================================================================

Approved by: re/scottl
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
----------------------------
revision 1.15
date: 2004/10/08 14:48:02;  author: mtm;  state: Exp;  lines: +1 -4
Remove a reference to a non-existent syscall: _thr_exit(). The
actual name is thr_exit(). How this ever worked is beyond me.
----------------------------
revision 1.14
date: 2004/10/06 14:20:57;  author: mtm;  state: Exp;  lines: +2 -3
Close a race between a thread exiting and the freeing of it's stack.
After some discussion the best option seems to be to signal the thread's
death from within the kernel. This requires that thr_exit() take an
argument.

Discussed with: davidxu, deischen, marcel
MFC after: 3 days
=============================================================================

Approved by: re/scottl
</pre>
</div>
</content>
</entry>
<entry>
<title>Make libthr async-signal-safe without costly signal masking. The guidlines I</title>
<updated>2004-05-20T12:06:16+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2004-05-20T12:06:16+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=4cd18a22d554e7205ddf0408badbda02411ed51e'/>
<id>4cd18a22d554e7205ddf0408badbda02411ed51e</id>
<content type='text'>
followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate,
pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of
the rest of the pthread api is required to be async-signal-safe. This means
that only the three mentioned functions are safe to use from inside
signal handlers.
However, there are certain system/libc calls that are
cancellation points that a caller may call from within a signal handler,
and since they are cancellation points calls have to be made into libthr
to test for cancellation and exit the thread if necessary. So, the
cancellation test and thread exit code paths must be async-signal-safe
as well. A summary of the changes follows:

o Almost all of the code paths that masked signals, as well as locking the
  pthread structure now lock only the pthread structure.
o Signals are masked (and left that way) as soon as a thread enters
  pthread_exit().
o The active and dead threads locks now explicitly require that signals
  are masked.
o Access to the isdead field of the pthread structure is protected by both
  the active and dead list locks for writing. Either one is sufficient for
  reading.
o The thread state and type fields have been combined into one three-state
  switch to make it easier to read without requiring a lock. It doesn't need
  a lock for writing (and therefore for reading either) because only the
  current thread can write to it and it is an integer value.
o The thread state field of the pthread structure has been eliminated. It
  was an unnecessary field that mostly duplicated the flags field, but
  required additional locking that would make a lot more code paths require
  signal masking. Any truly unique values (such as PS_DEAD) have been
  reborn as separate members of the pthread structure.
o Since the mutex and condvar pthread functions are not async-signal-safe
  there is no need to muck about with the wait queues when handling
  a signal ...
o ... which also removes the need for wrapping signal handlers and sigaction(2).
o The condvar and mutex async-cancellation code had to be revised as a result
  of some of these changes, which resulted in semi-unrelated changes which
  would have been difficult to work on as a separate commit, so they are
  included as well.

The only part of the changes I am worried about is related to locking for
the pthread joining fields. But, I will take a closer look at them once this
mega-patch is committed.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate,
pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of
the rest of the pthread api is required to be async-signal-safe. This means
that only the three mentioned functions are safe to use from inside
signal handlers.
However, there are certain system/libc calls that are
cancellation points that a caller may call from within a signal handler,
and since they are cancellation points calls have to be made into libthr
to test for cancellation and exit the thread if necessary. So, the
cancellation test and thread exit code paths must be async-signal-safe
as well. A summary of the changes follows:

o Almost all of the code paths that masked signals, as well as locking the
  pthread structure now lock only the pthread structure.
o Signals are masked (and left that way) as soon as a thread enters
  pthread_exit().
o The active and dead threads locks now explicitly require that signals
  are masked.
o Access to the isdead field of the pthread structure is protected by both
  the active and dead list locks for writing. Either one is sufficient for
  reading.
o The thread state and type fields have been combined into one three-state
  switch to make it easier to read without requiring a lock. It doesn't need
  a lock for writing (and therefore for reading either) because only the
  current thread can write to it and it is an integer value.
o The thread state field of the pthread structure has been eliminated. It
  was an unnecessary field that mostly duplicated the flags field, but
  required additional locking that would make a lot more code paths require
  signal masking. Any truly unique values (such as PS_DEAD) have been
  reborn as separate members of the pthread structure.
o Since the mutex and condvar pthread functions are not async-signal-safe
  there is no need to muck about with the wait queues when handling
  a signal ...
o ... which also removes the need for wrapping signal handlers and sigaction(2).
o The condvar and mutex async-cancellation code had to be revised as a result
  of some of these changes, which resulted in semi-unrelated changes which
  would have been difficult to work on as a separate commit, so they are
  included as well.

The only part of the changes I am worried about is related to locking for
the pthread joining fields. But, I will take a closer look at them once this
mega-patch is committed.
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove the garbage collector thread. All resources are freed</title>
<updated>2004-03-28T14:05:28+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2004-03-28T14:05:28+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=1c6f63018d08de4401f8f07c371487958ae4121c'/>
<id>1c6f63018d08de4401f8f07c371487958ae4121c</id>
<content type='text'>
in-line. If the exiting thread cannot release a resource, then
the next thread to exit will release it.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
in-line. If the exiting thread cannot release a resource, then
the next thread to exit will release it.
</pre>
</div>
</content>
</entry>
<entry>
<title>Implement reference counting of read-write locks. This uses</title>
<updated>2004-01-19T14:51:45+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2004-01-19T14:51:45+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=c40bafac85090c48459be8ad7d6ef854aa305da2'/>
<id>c40bafac85090c48459be8ad7d6ef854aa305da2</id>
<content type='text'>
a list in the thread structure to keep track of the locks and
how many times they have been locked. This list is checked
on every lock and unlock. The traversal through the list is
O(n). Most applications don't hold so many locks at once that
this will become a problem. However, if it does become a problem
it might be a good idea to review this once libthr is
off probation and in the optimization cycle.
This fixes:
	o deadlock when a thread tries to recursively acquire a
	  read lock when a writer is waiting on the lock.
	o a thread could previously successfully unlock a lock it did not own
	o deadlock when a thread tries to acquire a write lock on
	  a lock it already owns for reading or writing [ this is admittedly
	  not required by POSIX, but is nice to have ]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
a list in the thread structure to keep track of the locks and
how many times they have been locked. This list is checked
on every lock and unlock. The traversal through the list is
O(n). Most applications don't hold so many locks at once that
this will become a problem. However, if it does become a problem
it might be a good idea to review this once libthr is
off probation and in the optimization cycle.
This fixes:
	o deadlock when a thread tries to recursively acquire a
	  read lock when a writer is waiting on the lock.
	o a thread could previously successfully unlock a lock it did not own
	o deadlock when a thread tries to acquire a write lock on
	  a lock it already owns for reading or writing [ this is admittedly
	  not required by POSIX, but is nice to have ]
</pre>
</div>
</content>
</entry>
<entry>
<title>Change all instances of THR_LOCK/UNLOCK, etc to UMTX_*.</title>
<updated>2003-07-06T10:18:48+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2003-07-06T10:18:48+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=659045ffbfab93ae8438b07e81c09da1271bd9d8'/>
<id>659045ffbfab93ae8438b07e81c09da1271bd9d8</id>
<content type='text'>
It is a more acurate description of the locks they
operate on.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
It is a more acurate description of the locks they
operate on.
</pre>
</div>
</content>
</entry>
<entry>
<title>Sweep through pthread locking and use the new locking primitives for</title>
<updated>2003-06-29T23:51:04+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2003-06-29T23:51:04+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=dbc6f4c07d5f2ea73bb7f1845acccd55049a60dd'/>
<id>dbc6f4c07d5f2ea73bb7f1845acccd55049a60dd</id>
<content type='text'>
libthr.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
libthr.
</pre>
</div>
</content>
</entry>
<entry>
<title>Don't hold the active thread list lock when signaling the gc thread.</title>
<updated>2003-05-29T20:46:53+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2003-05-29T20:46:53+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=b3cdf7ae2eb9a89e6f906aad132866185cf4dfe8'/>
<id>b3cdf7ae2eb9a89e6f906aad132866185cf4dfe8</id>
<content type='text'>
The dead list thread is sufficient for synchronization.

Retire the arch_id (ldt array slot) in the gc thread instead of the
doing it in the thread itself.

Approved by:	re/jhb
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The dead list thread is sufficient for synchronization.

Retire the arch_id (ldt array slot) in the gc thread instead of the
doing it in the thread itself.

Approved by:	re/jhb
</pre>
</div>
</content>
</entry>
<entry>
<title>Minimize the potential for deadlocks between an exiting thread and it's</title>
<updated>2003-05-27T21:48:42+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2003-05-27T21:48:42+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=a09d02f780d6aac0bdd6d86cb0cce6e91198b407'/>
<id>a09d02f780d6aac0bdd6d86cb0cce6e91198b407</id>
<content type='text'>
joiner by making sure all locks and unlocks occur in the same order. For
the record the lock order is: DEAD_LIST, THREAD_LIST, exiting thread, joiner
thread.

Approved by: re/rwatson
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
joiner by making sure all locks and unlocks occur in the same order. For
the record the lock order is: DEAD_LIST, THREAD_LIST, exiting thread, joiner
thread.

Approved by: re/rwatson
</pre>
</div>
</content>
</entry>
<entry>
<title>Start locking up the active and dead threads lists. The active threads</title>
<updated>2003-05-25T08:31:33+00:00</updated>
<author>
<name>Mike Makonnen</name>
<email>mtm@FreeBSD.org</email>
</author>
<published>2003-05-25T08:31:33+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=71d09bc86add29bb88cb5cf14e1403077f9b512c'/>
<id>71d09bc86add29bb88cb5cf14e1403077f9b512c</id>
<content type='text'>
list is protected by a spinlock_t, but the dead list uses a pthread_mutex
because it is necessary to synchronize other threads with the garbage
collector thread. Lock/Unlock macros are used so it's easier to make
changes to the locks in the future.

The 'dead thread list' lock is intended to replace the gc mutex.
This doesn't have any practical ramifications. It simply makes it
clearer what the purpose of the lock is. The gc will use this lock,
instead of the gc mutex, to synchronize access to the dead list with
other threads.

Modify _pthread_exit() to use these two new locks instead of GIANT_LOCK,
and also to properly lock and protect thread state changes,
especially with respect to a joining thread.

The gc thread was also re-arranged to be more organized and less nested.

_pthread_join() was also modified to use the thread list locks. However,
locking and unlocking here needs special care because a thread could find
itself in a position where it's joining an exiting thread that is
waiting on the dead list lock, which this thread (joiner) holds. If the
joiner doesn't take care to lock *and* unlock in the same order they
(the joiner and the joinee) could deadlock against each other.

Approved by:	re/blanket libthr
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
list is protected by a spinlock_t, but the dead list uses a pthread_mutex
because it is necessary to synchronize other threads with the garbage
collector thread. Lock/Unlock macros are used so it's easier to make
changes to the locks in the future.

The 'dead thread list' lock is intended to replace the gc mutex.
This doesn't have any practical ramifications. It simply makes it
clearer what the purpose of the lock is. The gc will use this lock,
instead of the gc mutex, to synchronize access to the dead list with
other threads.

Modify _pthread_exit() to use these two new locks instead of GIANT_LOCK,
and also to properly lock and protect thread state changes,
especially with respect to a joining thread.

The gc thread was also re-arranged to be more organized and less nested.

_pthread_join() was also modified to use the thread list locks. However,
locking and unlocking here needs special care because a thread could find
itself in a position where it's joining an exiting thread that is
waiting on the dead list lock, which this thread (joiner) holds. If the
joiner doesn't take care to lock *and* unlock in the same order they
(the joiner and the joinee) could deadlock against each other.

Approved by:	re/blanket libthr
</pre>
</div>
</content>
</entry>
</feed>
