Commit Graph

156 Commits

Author SHA1 Message Date
jb
15613e5465 Ensure that an existing thread gets it's state set to PS_DEAD to
prevent being rescheduled.

Submitted by: Dan Eischen <eischen@vigrid.com>
1999-05-16 05:25:37 +00:00
nate
6954111347 - Fixed bug where we NULL'd before we freed the data causing a memory leak.
Submitted by:	 Ralf S. Engelschall
Obtained from:	PR i386/11713
1999-05-14 21:36:16 +00:00
alex
3c8ad88c51 Removed extraneous comma in xrefs. 1999-05-14 21:03:23 +00:00
alex
1ba5140a5a Added missing comma in xrefs. 1999-05-14 21:03:11 +00:00
jb
0d7925ce92 Mutex test program.
Submitted by: Daniel Eischen <eischen@vigrid.com>
1999-05-09 07:55:24 +00:00
jb
a7fbc7e55e Add mutex test program. 1999-05-09 07:50:31 +00:00
jasone
b917271c13 Back out patch for cond_timedwait() bug from -current, since other changes
have made the patch obsolete, as pointed out by Daniel Eischen
<eischen@vigrid.com>.

PR:		bin/8872
1999-05-08 07:50:05 +00:00
jasone
2082f1dfa2 Apply patch included in bin/8872. This fixes a bug that occurs when
pthread_cond_timedwait() times out.

PR:		bin/8872
Submitted by:	Jason Evans <jasone@canonware.com>
Reviewed by:	David Schwartz <davids@webmaster.com>
1999-05-07 07:59:44 +00:00
jb
282edeefd2 [ The author's description... ]
o Runnable threads are now maintained in priority queues.  The
    implementation requires two things:

      1.) The priority queues must be protected during insertion
          and removal of threads.  Since the kernel scheduler
          must modify the priority queues, a spinlock for
          protection cannot be used.   The functions
          _thread_kern_sched_defer() and _thread_kern_sched_undefer()
          were added to {un}defer kernel scheduler activation.

      2.) A thread (active) priority change can be performed only
          when the thread is removed from the priority queue.  The
          implementation uses a threads active priority when
          inserting it into the queue.

    A by-product is that thread switches are much faster.  A
    separate queue is used for waiting and/or blocked threads,
    and it is searched at most 2 times in the kernel scheduler
    when there are active threads.  It should be possible to
    reduce this to once by combining polling of threads waiting
    on I/O with the loop that looks for timed out threads and
    the minimum timeout value.

  o Functions to defer kernel scheduler activation were added.  These
    are _thread_kern_sched_defer() and _thread_kern_sched_undefer()
    and may be called recursively.  These routines do not block the
    scheduling signal, but latch its occurrence.  The signal handler
    will not call the kernel scheduler when the running thread has
    deferred scheduling, but it will be called when running thread
    undefers scheduling.

  o Added support for _POSIX_THREAD_PRIORITY_SCHEDULING.  All the
    POSIX routines required by this should now be implemented.
    One note, SCHED_OTHER, SCHED_FIFO, and SCHED_RR are required
    to be defined by including pthread.h.  These defines are currently
    in sched.h.  I modified pthread.h to include sched.h but don't
    know if this is the proper thing to do.

  o Added support for priority protection and inheritence mutexes.
    This allows definition of _POSIX_THREAD_PRIO_PROTECT and
    _POSIX_THREAD_PRIO_INHERIT.

  o Added additional error checks required by POSIX for mutexes and
    condition variables.

  o Provided a wrapper for sigpending which is marked as a hidden
    syscall.

  o Added a non-portable function as a debugging aid to allow an
    application to monitor thread context switches.  An application
    can install a routine that gets called everytime a thread
    (explicitly created by the application) gets context switched.
    The routine gets passed the pthread IDs of the threads that are
    being switched in and out.

Submitted by: Dan Eischen <eischen@vigrid.com>

Changes by me:

  o Added a PS_SPINBLOCK state to deal with the priority inversion
    problem most often (I think) seen by threads calling malloc/free/realloc.

  o Dispatch signals to the running thread directly rather than at a
    context switch to avoid the situation where the switch never occurs.
1999-03-23 05:07:56 +00:00
alex
3792132308 Typo fix (set --> get).
Obtained from:	OpenBSD (David Leonard)
1999-03-22 23:13:37 +00:00
bde
263c045b9d Fixed bitrot in synopsis (some const poisoning hadn't reached here). 1999-03-05 18:43:00 +00:00
jb
db8e67c81d Increase the size of private thread flags so that the test for a
thread trying to call pthread_exit() from a cleanup handler actually
works.

Submitted by: David Leonard <david.leonard@csee.uq.edu.au> OpenBSD
1999-01-15 00:21:03 +00:00
imp
2a38c2c82e Fix a minor security problem in libc_r.
Submitted by: Alexandre Snarskii <snar@paranoia.ru>
Approved by: John Birrell
Reminded me that I'd been sitting on this too long: snar@paranoia.ru
1999-01-11 00:02:37 +00:00
jb
09291c2abe Don't hide mknod, it doesn't need a wrapper and never has had one. 1998-12-10 20:27:52 +00:00
eivind
22f53707dd Add support for pthread_mutexattr_settype(). As a side effect of
testing this, fix MUTEX_TYPE_COUNTING_FAST.  Recursive locks now work.
1998-11-28 23:52:58 +00:00
jb
c2efe498b5 Interrupt threads waiting in select etc.
Submitted by: Alec Wolman <wolman@cs.washington.edu>
1998-11-15 10:01:34 +00:00
jb
146a1c4dd1 Close a window between unlocking a spinlock and changing the thread state. 1998-11-15 09:58:26 +00:00
dt
85c0134e6e Don't call pthread_mutex_lock with _SPINLOCK held.
Made pthread_cond_wait() more similar to pthread_cond_timedwait().

PR:		8375
1998-11-06 21:04:02 +00:00
dt
0af6de3235 Fix some bugs in pthread scheduler:
make pthread_yield() more reliable,
  threads always (I hope) preempted at least every 0.1 sec, as intended.

PR:		bin/7744
Submitted by:	"Richard Seaman, Jr." <dick@tar.com>
1998-10-09 19:01:30 +00:00
dt
393632f09d Debug when an environment variable set, no when it is unset. 1998-09-30 19:17:51 +00:00
jb
bd80c186a2 Revise test code for sigwait and add test code for sigsuspend.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-09-30 07:14:02 +00:00
jb
3d6ff09f8f Revise test code for sigwait and add test code for sigsuspend.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-09-30 07:08:09 +00:00
jb
376c5036ba Fix a comment. 1998-09-30 06:42:29 +00:00
jb
f83e5589d8 Cosmetic cleansing. This code requires extra work to keep the garbage
collector thread running after a fork.
1998-09-30 06:41:16 +00:00
jb
f1dac2e4d8 Move the cleanup code that frees memory allocated for a dead thread from
the thread kernel into a garbage collector thread which is started when
the fisrt thread is created (other than the initial thread). This
removes the window of opportunity where a context switch will cause a
thread that has locked the malloc spinlock, to enter the thread kernel,
find there is a dead thread and try to free memory, therefore trying
to lock the malloc spinlock against itself.

The garbage collector thread acts just like any other thread, so
instead of having a spinlock to control accesses to the dead thread
list, it uses a mutex and a condition variable so that it can happily
wait to be signalled when a thread exists.
1998-09-30 06:36:56 +00:00
jb
3abf25de7a Use snprintf instead of sprintf to avoid long source file paths from
launching an application into space when someone tries to debug it.

The dead thread list now has it's own link pointer, so use that when
reporting the grateful dead.
1998-09-30 06:29:54 +00:00
jb
63437559be Implementation of an additional state called SIGWAIT (with the previous
one renamed to SIGSUSPEND) to fix sigwait().

Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-09-30 06:27:31 +00:00
jb
38b43562a8 NULL a pointer after it is freed to avoid trying to free it again. 1998-09-30 06:24:57 +00:00
jb
f462ccb1ac - Fix the debug macros.
-  Add support of a thread being listed in the dead thread list as well
   as the thread list.
-  Add a new thread state to make sigwait work properly. (Submitted by
   Daniel M. Eischen <eischen@vigrid.com>)
-  Add global variable for the garbage collector mutex and condition
   variable.
-  Delete a couple of prototypes that are no longer required.
-  Add a prototype for the garbage collector thread.
1998-09-30 06:22:07 +00:00
dfr
96e7b502ec Change to a code sequence which is more likely to work on SMP systems.
Now all I need is an alpha SMP box to port FreeBSD to :-)
1998-09-16 09:27:05 +00:00
dt
9413745ea6 Don't clobber errno if we are not going to fail. 1998-09-13 15:33:42 +00:00
dt
b63858bd9d Don't lock newfd if it is not opened.
PR:		5961
1998-09-13 12:48:47 +00:00
dt
6c8d2b9af4 In libc_r, rename vfork syscall to _thread_sys_vfork and make vfork an alias
to fork. It is difficult to do real vfork in libc_r, since almost every
operation with file descriptsor changes _thread_fd_table and friends.

popen(3) works much better with this change.
1998-09-12 22:03:20 +00:00
dt
fd3bb97167 Fixed bug, caused threads to wait for locks which nobody hold.
Fixed sign extension bug, caused undefined behavior if FILE live in stack.
1998-09-09 16:50:33 +00:00
alex
b77f77e32b Removed unused variables. 1998-09-07 21:55:01 +00:00
alex
5ca8a87f0a Removed some variable initializations which were unnecessary and divergent
from style(9).
1998-09-07 21:07:59 +00:00
alex
a59b3a7327 -Wall clean. 1998-09-07 19:23:55 +00:00
alex
90a31b51e3 Implement pthread read/write locks as defined by Version 2 of the Single
UNIX Specification.

As with our standard mutexes, process shared locks are not supported at
this time.
1998-09-07 19:01:43 +00:00
wosch
a024876276 Sort cross references. 1998-08-31 16:41:09 +00:00
jb
7350d9dfef Don't automatically restart syscalls for the signals that the thread
kernel needs.
1998-08-26 20:55:31 +00:00
jb
906d62272c Back out most of the last commit. It created problems with sigpause. 1998-08-26 20:50:42 +00:00
jb
ce1dfea1c4 Test program for sigwait.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-08-25 12:35:16 +00:00
jb
1430b5a61c Add support for building test programs. 1998-08-25 12:33:22 +00:00
jb
2e85bdc1b9 Fix for sigwait problem.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
PR:           misc/7039
1998-08-25 11:19:14 +00:00
jdp
7dc22f67d7 Add missing initialization of the length variable passed to
getsockopt().  Use a separate variable for clarity, instead of
overloading an unrelated variable.
1998-08-12 20:29:29 +00:00
jb
a7ead657ce Add extra initialisation code that is required for processes that
are started instead of init (pid = 1). This allows an embedded
implementation quite like VxWorks, with (possibly) a single threaded
program running instead of init. The neat thing is that the same threaded
process can run in a multi-user workstation environment too.
1998-08-10 01:24:22 +00:00
bde
ea2b556e59 Changed prototype in synopsis to match prototype in <pthread.h>. 1998-08-03 16:54:51 +00:00
alex
4bdfb1c8a2 The pthreads standard has been published. Change:
...is expected to conform to IEEE (``POSIX'') Std 1003.1c when it is
   published.
to:
   ...conforms to ISO/IEC 9945-1 ANSI/IEEE (``POSIX'') Std 1003.1 Second
   Edition 1996-07-12.

Discussed with:	jb
1998-08-03 00:58:37 +00:00
alex
60c3bc0d8c A style fix for my previous commit. 1998-08-02 23:07:25 +00:00
alex
b5ebac71c7 Fixed a race condition during the first lock/trylock of a statically
initialized mutex.  Statically initialized mutexes are actually
initialized at first use (pthread_mutex_lock/pthread_mutex_trylock).
To prevent concurrent initialization by multiple threads, all
static initializations are now serialized by a spinlock.

Reviewed by:	jb
1998-08-02 17:04:25 +00:00