Commit Graph

55 Commits

Author SHA1 Message Date
christos 3ca3d0b1e7 add a missing volatile. 2007-01-20 04:56:07 +00:00
ad b8daad9836 Fix a race between pthread_exit() and pthread_join(). 2007-01-16 05:22:55 +00:00
ad efb1fc06e2 Fix a race between pthread_create() and pthread_exit() in the 1:1 case. 2007-01-16 04:19:02 +00:00
ad 39aa27f5ce Pass in the 'hint' argument when parking/unparking LWPs. 2007-01-16 01:35:16 +00:00
ad ded2602507 Fix bugs with and improve upon previous. 2006-12-24 18:39:45 +00:00
ad fe9718ac7c Add another comment. 2006-12-23 09:48:18 +00:00
ad 10058f19c8 Add a comment. 2006-12-23 05:18:56 +00:00
ad 1ac6a89b79 Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
2006-12-23 05:14:46 +00:00
drochner f782e99583 There is no point in using the internal sigprocmask() to initialize
the process' signal mask -- this ends up in a no-op.
Use the system call directly instead.
(This might be done in pthread_sig.c, but for now I wanted a simple
patch which is easily tested and pulled up.)
2006-04-24 18:39:36 +00:00
yamt 9f9e6a32dd - do PTHREAD_MLOCK_KLUDGE in pthread__stackid_setup, rather than callers,
so that the main thread is not different from others.
  as a side effect, fix memory leak in pthread_create on error.
- make pthread__stackid_setup return a error rather than calling err(2).
2006-02-12 11:41:53 +00:00
chs 3ad2320789 if mlock() fails in pthread_create(), return EAGAIN instead of
failing an assertion.
2005-10-19 02:44:45 +00:00
chs 0e67554241 starting the pthread library (ie. calling pthread__start()) before
any threads are created turned out to be not such a good idea.
there are stronger requirements on what has to work in a forked child
while a process is still single-threaded.  so take all that stuff
back out and fix the problems with single-threaded programs that
are linked with libpthread differently, by checking if the library
has been started and doing completely different stuff if it hasn't been:
 - for pthread_rwlock_timedrdlock(), just fail with EDEADLK immediately.
 - for sem_wait(), the only thing that can unlock the semaphore is a
   signal handler, so use sigsuspend() to wait for a signal.
 - for pthread_mutex_lock_slow(), just go into an infinite loop
   waiting for signals.

I also noticed that there's a "sem2" test that has never worked in its
single-threaded form.  the problem there is that a signal handler tries
to take a sem_t interlock which is already held when the signal is received.
fix this too, by adding a single-threaded case for sig_trywait() that
blocks signals instead of using the userland interlock.
2005-10-19 02:15:03 +00:00
chs ba70e96a09 in pthread_kill() and pthread_suspend_np(), return without doing anything
if the target thread is a zombie.

in all the functions that didn't do so already, verify a pthread_t before
dereferencing it (under #ifdef ERRORCHECK, since these checks are not
mandated by the standard).

clean up some debugging stuff.
2005-10-16 00:37:52 +00:00
chs 2415c56ed0 in pthread_mutex_lock_slow(), pthread_rwlock_timedrdlock() and sem_wait(),
call pthread__start() if it hasn't already been called.  this avoids
an internal assertion from the library if these routines are used
before any threads are created and they need to sleep.
fixes PR 20256, PR 24241, PR 25722, PR 26096.
2005-10-16 00:07:24 +00:00
yamt 9493e4bf43 make this compile without PTHREAD_MLOCK_KLUDGE. 2005-07-01 12:35:18 +00:00
nathanw 916de87872 Keep the kernel updated with signal action signal masks (act.sa_mask) until
threads are started, since before that the traditional signal invocation
method will be used. Fixes regress/lib/libpthread/sigmask2.
2005-02-26 20:33:06 +00:00
christos b35aef8d4b Default back pthread__concurrency to 1 until we fix the regression test
related to pthread_kill().
2005-02-10 23:42:37 +00:00
christos 3a610280bb If $PTHREAD_CONCURRENCY is not set, set it to ncpu 2005-02-10 02:20:49 +00:00
christos cca9405683 Add charles' mlock fixes, protected with PTHREAD_MLOCK_KLUDGE and enabled
by default, until we come up with a real fix.
2005-02-03 17:30:33 +00:00
mycroft 75a9478818 Add some additional assertions and debugging printf()s. 2005-01-06 17:38:29 +00:00
yamt 6b2b9c625f - fix pthread_detach with an already exit'ed thread.
namely, put the thread to deadqueue rather than just leaking it.
- fix a race between pthread_detach/join and pthread_exit,
  which also causes dead thread leaks.
2004-08-12 10:54:13 +00:00
chs 94a458cedd enhance MI pthreads code to support hppa:
- statically initialize all global spin locks.  on hppa, 0 means
   the lock is held, so leaving them with the default value doesn't work.
 - compare functions pointers using a function-pointer type rather than
   an integral type.  on hppa, function pointers may be indirect,
   so we need to trigger gcc to emit calls to the function-pointer
   canonicalization routines in the millicode.
 - on hppa the stack grows up, so handle that using the STACK_* macros.
2004-07-18 21:24:52 +00:00
drochner 0e6c93b9fa const'ify the arguments to pthread__assertfunc and _errorfunc;
needed because the __func__ pseudo-var is strictly "const*" in gcc-3.4
2004-06-25 16:33:32 +00:00
cl f2f106648c add libpthread part of concurrency support for SA on MP systems
- enable concurrency according to environment variable PTHREAD_CONCURRENCY
- add idle VP wakeup if there are additional jobs and idle VPs
- make reidlequeue per VP
- enable spinning for locks
- fix race condition in alarm processing
- fix race condition in mutex locking
- make debugging output line buffered and add VP prefix to debug lines
2004-03-14 01:19:41 +00:00
cl 82b6b2dbda Handle block/unblock for threads in critical section without
sa_unblockyield.

XXX g/c sa_unblockyield in kernel later
2003-12-31 16:45:48 +00:00
christos b7559f8576 PR/23791: Patrick Latify: Fix memory leak on thread creation failure. 2003-12-18 15:39:56 +00:00
christos 38b1c6f405 Add:
int    pthread_attr_setcreatesuspend_np(pthread_attr_t *);
int    pthread_suspend_np(pthread_t);
int    pthread_resume_np(pthread_t);

needed for java. Approved and fixed by cl.
2003-11-09 18:56:48 +00:00
nathanw bd9a18b79f Split out pthread_{set,get}specific() into a separate file and arrange
for that file to not be built with profiling. This makes it reasonable to
use pthread_{set,get}specific() to implement thread-safe profiline call counts.
2003-08-13 18:52:01 +00:00
nathanw 0878df5d25 Lock accesses to pt_flags and pt_cancel.
When disabling cancellation, clear the pt_cancel flag if it was set
and note the cancellation request with PT_FLAG_CS_PENDING. This avoids
a problem where a cancellation request entered but not acted upon before
pthread_setcanclstate(PTHREAD_CANCEL_DISABLE) is called would still be
aceted upon before cancellation was re-enabled.
2003-07-21 22:24:09 +00:00
nathanw 0c96790183 Use _sys_write() instead of write() in the assertion and error
functions, to avoid invoking the cancellation machinery in the middle
of trying to print an assertion or error message.
2003-07-21 22:17:14 +00:00
nathanw 68a63a4079 Move initialization of variable 'nthreads' so that pthread_exit() from
the main thread, with no other threads created, exits cleanly instead
of triggering an assertion in pthread_next().
2003-07-21 22:14:57 +00:00
nathanw ec2c169839 pthread.c was getting a bit unwieldly. Move pthread_attr stuff out
into a new file, and put the shared private structure definition in
pthread_int.h.
2003-07-18 22:33:45 +00:00
nathanw 0172694e7d Implement a bunch of pthread_attr_() functions, which genuinely set and examine
pthread_attr_t objects, although most of the properties being set don't really
affect threads yet:

pthread_attr_{get,set}guardsize()
pthread_attr_{get,set}inheritsched()
pthread_attr_{get,set}scope()
pthread_attr_{get,set}stack()
pthread_attr_setstack{size,addr}()

Remove some useless assertions and error checks in the existing pthread_attr()
routines.

Implement pthread_attr_get_np(), to examine the attributes of an existing
thread. Idea and interface from FreeBSD.

Change PTHREAD_ERRORMODE environment variable to PTHREAD_DIAGASSERT, and
make it behave like libc's LIBC_DIAGASSERT. The way to disable error-checking
and aborting is now "PTHREAD_DIAGASSERT=AEL", rather than
"PTHREAD_ERRORMODE=ignore".
2003-07-18 22:12:30 +00:00
nathanw 9e5c87057d Add strong alias for setcancelstate. 2003-07-18 21:57:26 +00:00
nathanw 487eb7e193 Initialize pt_trapuc in pthread__initthread(). 2003-06-26 01:30:39 +00:00
nathanw 877f89857f Tiny bit of infrastructure for ABI-supported thread-ID storage. 2003-06-06 21:06:07 +00:00
christos dc1665b80b Add pthread_attr_getstack{,size,addr} needed by jdk 2003-06-02 16:59:26 +00:00
christos 143f5a277a pass lint:
1. add new pthread__abort() and change pthread_assert(0) to it.
2. put constcond in the right place (in the macro).
3. no space after pthread__assert macro.
2003-05-27 15:24:24 +00:00
nathanw ff14fbf244 Move call to pthread__alarm_init() from pthread_init() (called at load
time) to pthread__start() (called on the first call of
pthread_create()), so that there's no opportunity for a fork() to
clear the per-process timer.

Problem pointed out by a test program from Mihai CHELARU on
current-users.
2003-04-28 17:46:30 +00:00
nathanw df2772713e Introduce a pthread__error() macro, for detected application errors as
opposed to internal errors. The setting of the PTHREAD_ERRORMODE
environment variable determines the runtime behavior. Valid settings
are "ignore", "abort", and "print". The default is currently "abort".
2003-04-23 19:35:47 +00:00
nathanw 2a4cef11ba When threads are started, register an atfork callback to clear
pthread__started in the child process. This lets sleep() work in the
child, as required by POSIX.
2003-04-07 21:29:48 +00:00
nathanw 37c11910ec Re-enable nanosleep(); kernel bug is squished (kern_time.c:1.67). 2003-03-10 22:16:36 +00:00
lukem f043c0fb57 add __RCSID() 2003-03-08 08:03:34 +00:00
nathanw a4314c450c Disable userlevel nanosleep() until I find the timer/alarm bug that it
is tickling.
2003-02-28 18:37:44 +00:00
nathanw 508a50ac15 In pthread_create(), rearrange name-setting code so that name is set
to NULL when the attribute structure does not have a private field
allocated.
2003-02-26 23:41:01 +00:00
thorpej b33971b9c3 Add support for naming a thread, using an API compatible with Tru64 Unix:
* pthread_attr_getname_np()
* pthread_attr_setname_np()
* pthread_getname_np()
* pthread_setname_np()

In addition to being query'able by the application (for log messages, etc.),
it is intended that these names can show up in the debugger.

Reviewed by nathanw.
2003-02-26 22:02:48 +00:00
nathanw 66fcc1ce38 In pthread_exit(), clear pt_canceled in addition to setting
PT_FLAG_CS_DISABLED in pt_flags.

Prevents cancellation cleanup handlers from thinking that they've been
canceled and exiting mid-handler. Problem spotted by Matt Thomas.
2003-02-22 00:53:29 +00:00
nathanw 8bcff70bb0 Define a pthread-specific assert function, pthread__assert(), that
bails out without trying to flush stdio buffers.
2003-02-15 04:34:40 +00:00
nathanw 96b5a26db2 Use pthread__sched_sleepers() instead of iterating over sleep queues
ourself.
2003-01-31 04:59:40 +00:00
drochner e81f9f1784 cosmetics 2003-01-29 14:03:08 +00:00