History log of /freebsd-10.0-release/lib/libkse/thread/thr_cancel.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 259065 07-Dec-2013 gjb

- Copy stable/10 (r259064) to releng/10.0 as part of the
10.0-RELEASE cycle.
- Update __FreeBSD_version [1]
- Set branch name to -RC1

[1] 10.0-CURRENT __FreeBSD_version value ended at '55', so
start releng/10.0 at '100' so the branch is started with
a value ending in zero.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 174689 16-Dec-2007 deischen

Remove hacks to allow libkse to export its symbols in the LIBTHREAD_1_0
version namespace which was needed before the library version was
bumped.


# 174112 30-Nov-2007 deischen

WARNS=3'ify.


# 172491 09-Oct-2007 obrien

Repo copy libpthreads to libkse.
This introduces the WITHOUT_LIBKSE nob,
and changes WITHOUT_LIBPTHREADS to mean with neither threading libs.
Approved by: re(kensmith)


# 156611 12-Mar-2006 deischen

Add compatibility symbol maps. libpthread (.so.1 and .so.2)
used LIBTHREAD_1_0 as its version definition, but now needs
to define its symbols in the same namespace used by libc.
The compatibility hooks allows you to use libraries and
binaries built and linked to libpthread before libc was
built with symbol versioning. The shims can be removed if
libpthread is given a version bump.

Reviewed by: davidxu


# 139023 18-Dec-2004 deischen

Use a generic way to back threads out of wait queues when handling
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


# 123312 09-Dec-2003 davidxu

Rename _thr_enter_cancellation_point to _thr_cancel_enter, rename
_thr_leave_cancellation_point to _thr_cancel_leave, add a parameter
to _thr_cancel_leave to indicate whether cancellation point should be
checked, this gives us an option to not check cancallation point if
a syscall successfully returns to avoid any leaks, current I have
creat(), open() and fcntl(F_DUPFD) to not check cancellation point
after they sucessfully returned.

Replace some members in structure kse with bit flags to same some
memory.

Conditionally compile THR_ASSERT to nothing if _PTHREAD_INVARIANTS is
not defined.

Inline some small functions in thr_cancel.c.

Use __predict_false in thr_kern.c for some executed only once code.

Reviewd by: deischen


# 120897 07-Oct-2003 davidxu

Fix some comments for last commit.


# 120895 07-Oct-2003 davidxu

Use thread lock instead of scheduler lock to eliminate lock contention
for all wrapped syscalls under SMP.

Reviewed by: deischen


# 118744 10-Aug-2003 davidxu

If thread mode is not activated yet, don't do extra work.

Reviewed by: deischen


# 118510 05-Aug-2003 deischen

Rethink the MD interfaces for libpthread to account for
archs that can (or are required to) have per-thread registers.

Tested on i386, amd64; marcel is testing on ia64 and will
have some follow-up commits.

Reviewed by: davidxu


# 117907 23-Jul-2003 deischen

Move idle kse wakeup to outside of regions where locks are held.
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 & Tested by: davidxu


# 117706 17-Jul-2003 davidxu

o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now it
is system bound thread and when it is blocked, no upcall is generated.

o Add ability to libkse to allow it run in pure 1:1 threading mode,
defining SYSTEM_SCOPE_ONLY in Makefile can turn on this option.

o Eliminate code for installing dummy signal handler for sigwait call.

o Add hash table to find thread.

Reviewed by: deischen


# 117300 07-Jul-2003 davidxu

Avoid accessing user provided parameters in critical region.

Reviewed by: deischen


# 117162 02-Jul-2003 davidxu

Fix typo.


# 116972 28-Jun-2003 davidxu

if thread is exiting, just returns. kse_thr_interrupt interface
was changed, it needs signal parameter, pass -1 to it, it indicates to
interrupt syscall.

Reviewed by: deischen


# 115278 24-May-2003 deischen

Change low-level locking a bit so that we can tell if
a lock is being waitied on.

Fix a races in join and cancellation.

When trying to wait on a CV and the library is not yet
threaded, make it threaded so that waiting actually works.

When trying to nanosleep() and we're not threaded, just
call the system call nanosleep instead of adding the thread
to the wait queue.

Clean up adding/removing new threads to the "all threads queue",
assigning them unique ids, and tracking how many active threads
there are. Do it all when the thread is added to the scheduling
queue instead of making pthread_create() know how to do it.

Fix a race where a thread could be marked for signal delivery
but it could be exited before we actually add the signal to it.

Other minor cleanups and bug fixes.

Submitted by: davidxu
Approved by: re@ (blanket for libpthread)


# 114767 05-May-2003 deischen

Make pthread_join() async-cancel-safe. David was going to commit
this, but I think he's asleep and want to be sure it gets in before
the freeze.

Submitted by: davidxu


# 114187 28-Apr-2003 deischen

o Don't add a scope system thread's KSE to the list of available
KSEs when it's thread exits; allow the GC handler to do that.

o Make spinlock/spinlock critical regions.

The following were submitted by davidxu

o Alow thr_switch() to take a null mailbox argument.

o Better protect cancellation checks.

o Don't set KSE specific data when creating new KSEs; rely on the
first upcall of the KSE to set it.

o Add the ability to set the maximum concurrency level and do this
automatically. We should have a way to enable/disable this with
some sort of tunable because some applications may not want this
to be the default.

o Hold the scheduling lock across thread switch calls.

o If scheduling of a thread fails, make sure to remove it from the list
of active threads.

o Better protect accesses to a joining threads when the target thread is
exited and detached.

o Remove some macro definitions that are now provided by <sys/kse.h>.

o Don't leave the library in threaded mode if creation of the initial
KSE fails.

o Wakeup idle KSEs when there are threads ready to run.

o Maintain the number of threads active in the priority queue.


# 113658 18-Apr-2003 deischen

Revamp libpthread so that it has a chance of working in an SMP
environment. This includes support for multiple KSEs and KSEGs.

The ability to create more than 1 KSE via pthread_setconcurrency()
is in the works as well as support for PTHREAD_SCOPE_SYSTEM threads.
Those should come shortly.

There are still some known issues which davidxu and I are working
on, but it'll make it easier for us by committing what we have.

This library now passes all of the ACE tests that libc_r passes
with the exception of one. It also seems to work OK with KDE
including konqueror, kwrite, etc. I haven't been able to get
mozilla to run due to lack of java plugin, so I'd be interested
to see how it works with that.

Reviewed by: davidxu


# 111035 17-Feb-2003 mini

Deliver signals posted via an upcall to the appropriate thread.


# 103419 16-Sep-2002 mini

Make libpthread KSE aware.

Reviewed by: deischen, julian
Approved by: -arch


# 103388 16-Sep-2002 mini

Make the changes needed for libpthread to compile in its new home.
The new libpthread will provide POSIX threading support using KSE.
These files were previously repo-copied from src/lib/libc_r.

Reviewed by: deischen
Approved by: -arch


# 97204 24-May-2002 deischen

Revamp suspend and resume. While I'm here add pthread_suspend_all_np()
and pthread_resume_all_np(). These suspend and resume all threads except
the current thread, respectively. The existing functions pthread_single_np()
and pthread_multi_np(), which formerly had no effect, now exhibit the same
behaviour and pthread_suspend_all_np() and pthread_resume_all_np(). These
functions have been added mostly for the native java port.

Don't allow the uthread kernel pipe to use the same descriptors as
stdio. Mostily submitted by Oswald Buddenhagen <ossi@kde.org>.

Correct some minor style nits.


# 95947 02-May-2002 archie

Make sure calls to pthread_cancel() do not take effect if the target
thread is already exiting.

PR: bin/37614
Reviewed by: deischen
MFC after: 1 week


# 91762 06-Mar-2002 deischen

Properly clear the status of a join operation if the joining thread is
canceled or the joinee is detached.


# 88015 16-Dec-2001 deischen

When cancelling a thread while in a join operation, do not detach
the target thread of the join operation. This allows the cancelled
thread to detach the target thread in its cancellation handler.
This bug was found by Butenhof's cancel_subcontract test.

Reviewed by: jasone


# 87988 15-Dec-2001 deischen

Pull the target thread of a join operation from the correct place
when cancelling a thread.


# 81750 16-Aug-2001 jasone

Fix a bug in canceling joining threads.
Do not detach canceled threads.

Reported by: Arno Klaassen <arno@heho.snv.jussieu.fr>
Collaboration with: deischen


# 76909 20-May-2001 jasone

Instead of using a join queue for each thread, use a single pointer to
keep track of a joiner. POSIX only supports a single joiner, so this
simplification is acceptable.

At the same time, make sure to mark a joined thread as detached so that
its resources can be freed.

Reviewed by: deischen
PR: 24345


# 75369 10-Apr-2001 deischen

To be consistent, use the __weak_reference macro from <sys/cdefs.h>
instead of #pragma weak to create weak definitions.

Suggested by: bde


# 71581 24-Jan-2001 deischen

Add weak definitions for wrapped system calls. In general:

_foo - wrapped system call
foo - weak definition to _foo

and for cancellation points:

_foo - wrapped system call
__foo - enter cancellation point, call _foo(), leave
cancellation point
foo - weak definition to __foo

Change use of global _thread_run to call a function to get the
currently running thread.

Make all pthread_foo functions weak definitions to _pthread_foo,
where _pthread_foo is the implementation. This allows an application
to provide its own pthread functions.

Provide slightly different versions of pthread_mutex_lock and
pthread_mutex_init so that we can tell the difference between
a libc mutex and an application mutex. Threads holding mutexes
internal to libc should never be allowed to exit, call signal
handlers, or cancel.

Approved by: -arch


# 61681 14-Jun-2000 jasone

pthread_mutex_lock(), pthread_cond_trywait(), and pthread_cond_wait() are
not allowed to return EINTR, but use of pthread_suspend_np() could cause
EINTR to be returned. To fix this, restructure pthread_suspend_np() so that
it does not interrupt a thread that is waiting on a mutex or condition, and
keep enough state around that pthread_resume_np() can fix things up
afterwards.

Reviewed by: deischen


# 58094 15-Mar-2000 deischen

Fix pthread_suspend_np/pthread_resume_np. For the record, suspending a
thread waiting on an event (I/O, condvar, etc) will, when resumed using
pthread_resume_np, return with EINTR. For example, suspending and resuming
a thread blocked on read() will not requeue the thread for the read, but
will return -1 with errno = EINTR. If the suspended thread is in a critical
region, the thread is suspended as soon as it leaves the critical region.

Fix a bogon in pthread_kill() where a signal was being delivered twice
to threads waiting in sigwait().

Reported by (suspend/resume bug): jdp
Reviewed by: jasone


# 56277 19-Jan-2000 jasone

Implement continuations to correctly handle [sig|_]longjmp() inside of a
signal handler. Explicitly check for jumps to anywhere other than the
current stack, since such jumps are undefined according to POSIX.

While we're at it, convert thread cancellation to use continuations, since
it's cleaner than the original cancellation code.

Avoid delivering a signal to a thread twice. This was a pre-existing bug,
but was likely unexposed until these other changes were made.

Defer signals generated by pthread_kill() so that they can be delivered on
the appropriate stack. deischen claims that this is unnecessary, which is
likely true, but without this change, pthread_kill() can cause undefined
priority queue states and/or PANICs in [sig|_]longjmp(), so I'm leaving
this in for now. To compile this code out and exercise the bug, define
the _NO_UNDISPATCH cpp macro. Defining _PTHREADS_INVARIANTS as well will
cause earlier crashes.

PR: kern/14685
Collaboration with: deischen


# 54708 16-Dec-1999 deischen

Fix problems with cancellation while in critical regions.

o Cancellation flags were not getting properly set/cleared.
o Loops waiting for internal locks were not being exited
correctly by a cancelled thread.
o Minor spelling (cancelation -> cancellation) and formatting
corrections (missing tab).

Found by: tg
Reviewed by: jasone


# 53812 28-Nov-1999 alfred

add pthread_cancel, obtained from OpenBSD.

eischen (Daniel Eischen) added wrappers to protect against cancled
threads orphaning internal resources.

the cancelability code is still a bit fuzzy but works for test
programs of my own, OpenBSD's and some examples from ORA's books.

add readdir_r to both libc and libc_r

add some 'const' attributes to function parameters

Reviewed by: eischen, jasone