README revision 1.1
11.1SprovenThis pthread package is/will be based on the POSIX1003.4a Draft 7 pthread 21.1Sprovenstandard, and Frank Mullers paper on signal handelling presented 31.1Sprovenat the Winter 93 USENIX conference. 41.1Sproven 51.1SprovenIt is currently being designed and written by me, Chris Provenzano. 61.1SprovenAll bug, comments, and questions can be sent me at either 71.1Sprovenproven@athena.mit.edu or proven@sun-lamp.cs.berkeley.edu 81.1SprovenPlease don't send bugs or patches to any of the NetBSD mailing lists. 91.1Sproven 101.1SprovenThanks goes to John Carr jfc@mit.edu for porting this to the IBM/RT, 111.1Sprovenand for his bug reports and fixes. 121.1Sproven 131.1SprovenPORTING 141.1SprovenOne of the goals of this user space implementation of pthreads is that it 151.1Sprovenbe portable. I have minimized the ammount of assembler code necessary, 161.1Sprovenbut some is. 171.1Sproven 181.1SprovenIf you want to port it to another platform here are a few basic hints. 191.1Sproven 201.1SprovenThere are currently three files you'll have to creat for your 211.1Sprovenarchitecture, machdep.h, machdep.c and syscall.S. 221.1SprovenThe first two are necessary to get the context switch section of 231.1Sproventhe pthread package running, the third is for all the syscalls. 241.1Sproven 251.1SprovenTo do an initial port, create an appropriate machdep.h, and machdep.c 261.1Sprovenand define PTHREAD_INITIAL_PORT in the Makefile 271.1Sproven 281.1SprovenComment out references to the stdio package. 291.1Sproven 301.1SprovenINCLUDE FILES AND PORTING 311.1SprovenTo continue to make this package portable, some basic rules on includes 321.1Sprovenfiles must be followed. 331.1Sproven 341.1Sprovenpthread.h should be included first (if it is to be included). 351.1Sprovenmachdep.h should define size_t if the system doesn't define it already 361.1Sproven 371.1Sprovenstdio.h should not be included. It is included in pthread.h. 381.1Sproven 391.1Sprovenposix.h should be included last. This file is used to correct non 401.1SprovenPOSIX features, after everything else has been defined. 411.1Sproven 421.1SprovenINTERNAL LOCKING 431.1SprovenTo prevent deadlocks the following rules were used for locks. 441.1Sproven 451.1Sproven1. Local locks for mutex queues and other like things are only locked 461.1Sproven by running threads, at NO time will a local lock be held by 471.1Sproven a thread in a non running state. 481.1Sproven2. Only threads that are in a run state can attempt to lock another thread, 491.1Sproven this way, we can assume that the lock will be released shortly, and don't 501.1Sproven have to unlock the local lock. 511.1Sproven3. The only time a thread will have a pthread->lock and is not in a run 521.1Sproven state is when it is in the reschedule routine. 531.1Sproven4. The reschedule routine assumes all local locks have been released, 541.1Sproven there is a lock on the currently running thread (pthread_run), 551.1Sproven and that this thread is being rescheduled to a non running state. 561.1Sproven It is safe to unlock the currently running threads lock after it 571.1Sproven has been rescheduled. 581.1Sproven5. The reschedule routine locks the kernel, sets the state of the currently 591.1Sproven running thread, unlocks the currently running thread, calls the 601.1Sproven context switch routines. 611.1Sproven6 the kernel lock is used only ... 621.1Sproven 631.1Sproven 641.1Sproven7. The order of locking is ... 651.1Sproven 661.1Sproven1 local locks 671.1Sproven2 pthread->lock /* Assumes it will get it soon */ 681.1Sproven3 pthread_run->lock /* Assumes it will get it soon, but must release 2 */ 691.1Sproven4 kernel lock /* Currently assumes it will ALWAYS get it. */ 701.1Sproven 711.1Sproven8. The kernel lock will be changed to a spin lock for systems that 721.1Sprovenalready support kernel threads, this way we can mutiplex threads onto 731.1Sprovenkernel threads. 741.1Sproven9. There are points where the kernel is locked and it needs to get 751.1Sproveneither a local lock or a pthread lock, if at these points the code 761.1Sprovenfails to get the lock the kernel gives up and sets a flag which will 771.1Sprovenbe checked at a later point. 781.1Sproven10. Interrupts are dissabled while the kernel is locked, the interrupt 791.1Sprovenmask must be checked afterwards or cleared in some way, after interrputs 801.1Sprovenhave been reenabled, this allows back to back interrupts, but should always 811.1Sprovenavoid missing one. 821.1Sproven 831.1SprovenCopyright (c) 1993 Chris Provenzano. All rights reserved. 841.1Sproven 851.1SprovenThis product includes software developed by the Univeristy of California, 861.1SprovenBerkeley and its contributors. 87