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 questions, bugs or patches to any of the *BSD* 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, Greg Hudson and Mark Eichin for the 12testing they've done, and all the others. 13 14PORTING 15One of the goals of this user space implementation of pthreads is that it 16be portable. I have minimized the ammount of assembler code necessary, 17but some is. 18 19If you want to port it to another platform here are a few basic hints. 20 21There are currently three files you'll have to creat for your 22architecture, machdep.h, machdep.c and syscall.S. 23The first two are necessary to get the context switch section of 24the pthread package running, the third is for all the syscalls. 25 26To do an initial port, create an appropriate machdep.h, and machdep.c 27and define PTHREAD_INITIAL_PORT in the Makefile 28 29Comment out references to the stdio package. 30 31INCLUDE FILES AND PORTING 32To continue to make this package portable, some basic rules on includes 33files must be followed. 34 35pthread.h should be included first (if it is to be included). 36machdep.h should define size_t if the system doesn't define it already 37 38posix.h should be included last. This file is used to correct non 39POSIX features, after everything else has been defined. 40 41INTERNAL LOCKING 42To prevent deadlocks the following rules were used for locks. 43 441. Local locks for mutex queues and other like things are only locked 45 by running threads, at NO time will a local lock be held by 46 a thread in a non running state. 472. Only threads that are in a run state can attempt to lock another thread, 48 this way, we can assume that the lock will be released shortly, and don't 49 have to unlock the local lock. 503. The only time a thread will have a pthread->lock and is not in a run 51 state is when it is in the reschedule routine. 524. The reschedule routine assumes all local locks have been released, 53 there is a lock on the currently running thread (pthread_run), 54 and that this thread is being rescheduled to a non running state. 55 It is safe to unlock the currently running threads lock after it 56 has been rescheduled. 575. The reschedule routine locks the kernel, sets the state of the currently 58 running thread, unlocks the currently running thread, calls the 59 context switch routines. 606 the kernel lock is used only ... 61 62 637. The order of locking is ... 64 651 local locks 662 pthread->lock /* Assumes it will get it soon */ 673 pthread_run->lock /* Assumes it will get it soon, but must release 2 */ 684 kernel lock /* Currently assumes it will ALWAYS get it. */ 69 708. The kernel lock will be changed to a spin lock for systems that 71already support kernel threads, this way we can mutiplex threads onto 72kernel threads. 739. There are points where the kernel is locked and it needs to get 74either a local lock or a pthread lock, if at these points the code 75fails to get the lock the kernel gives up and sets a flag which will 76be checked at a later point. 7710. Interrupts are dissabled while the kernel is locked, the interrupt 78mask must be checked afterwards or cleared in some way, after interrputs 79have been reenabled, this allows back to back interrupts, but should always 80avoid missing one. 81 82Copyright (c) 1993 Chris Provenzano. All rights reserved. 83 84This product includes software developed by the Univeristy of California, 85Berkeley and its contributors. 86