xref: /netbsd-src/lib/libpthread/README (revision 89fc7bac0859332dbb6b0fd0833e74557beadc29)
1This pthread package is/will be based on the POSIX1003.4a Draft 7 pthread
2standard, and Frank Mullers paper on signal handelling presented
3at the Winter 93 USENIX conference.
4
5It is currently being designed and written by me, Chris Provenzano.
6All bug, comments, and questions can be sent me at either
7proven@athena.mit.edu or proven@sun-lamp.cs.berkeley.edu
8Please don't send bugs or patches to any of the NetBSD mailing lists.
9
10Thanks goes to John Carr jfc@mit.edu for porting this to the IBM/RT,
11and for his bug reports and fixes.
12
13PORTING
14One of the goals of this user space implementation of pthreads is that it
15be portable. I have minimized the ammount of assembler code necessary,
16but some is.
17
18If you want to port it to another platform here are a few basic hints.
19
20There are currently three files you'll have to creat for your
21architecture, machdep.h, machdep.c and syscall.S.
22The first two are necessary to get the context switch section of
23the pthread package running, the third is for all the syscalls.
24
25To do an initial port, create an appropriate machdep.h, and machdep.c
26and define PTHREAD_INITIAL_PORT in the Makefile
27
28Comment out references to the stdio package.
29
30INCLUDE FILES AND PORTING
31To continue to make this package portable, some basic rules on includes
32files must be followed.
33
34pthread.h should be included first (if it is to be included).
35machdep.h should define size_t if the system doesn't define it already
36
37stdio.h should not be included. It is included in pthread.h.
38
39posix.h should be included last. This file is used to correct non
40POSIX features, after everything else has been defined.
41
42INTERNAL LOCKING
43To prevent deadlocks the following rules were used for locks.
44
451.	Local locks for mutex queues and other like things are only locked
46	by running threads, at NO time will a local lock be held by
47	a thread in a non running state.
482.  Only threads that are in a run state can attempt to lock another thread,
49	this way, we can assume that the lock will be released shortly, and don't
50	have to unlock the local lock.
513.	The only time a thread will have a pthread->lock and is not in a run
52	state is when it is in the reschedule routine.
534.	The reschedule routine assumes all local locks have been released,
54	there is a lock on the currently running thread (pthread_run),
55	and that this thread is being rescheduled to a non running state.
56	It is safe to unlock the currently running threads lock after it
57	has been rescheduled.
585.	The reschedule routine locks the kernel, sets the state of the currently
59	running thread, unlocks the currently running thread, calls the
60	context switch routines.
616	the kernel lock is used only ...
62
63
647.	The order of locking is ...
65
661 local locks
672 pthread->lock			/* Assumes it will get it soon */
683 pthread_run->lock		/* Assumes it will get it soon, but must release 2 */
694 kernel lock			/* Currently assumes it will ALWAYS get it. */
70
718.	The kernel lock will be changed to a spin lock for systems that
72already support kernel threads, this way we can mutiplex threads onto
73kernel threads.
749.	There are points where the kernel is locked and it needs to get
75either a local lock or a pthread lock, if at these points the code
76fails to get the lock the kernel gives up and sets a flag which will
77be checked at a later point.
7810.	Interrupts are dissabled while the kernel is locked, the interrupt
79mask must be checked afterwards or cleared in some way, after interrputs
80have been reenabled, this allows back to back interrupts, but should always
81avoid missing one.
82
83Copyright (c) 1993 Chris Provenzano. All rights reserved.
84
85This product includes software developed by the Univeristy of California,
86Berkeley and its contributors.
87