diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-10-15 16:57:45 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-10-15 16:57:45 +0000 |
commit | c7848ba184fac8eca4125f4296d6e09fee2c1846 (patch) | |
tree | b3622e9e800badf79382bfc95e96ea8cd2733b5a /README.threads | |
parent | f826a10b5944692b2da706f4a0ac5056f28e8c6d (diff) | |
download | perl-c7848ba184fac8eca4125f4296d6e09fee2c1846.tar.gz |
Finish thread state machine: fixes global destruction of threads,
detaching, joining etc. Alter FAKE_THREADS-specific fields to use
new HAVE_THREAD_INTERN stuff. Updates docs. Various fixes to
Thread.xs.
p4raw-id: //depot/perl@131
Diffstat (limited to 'README.threads')
-rw-r--r-- | README.threads | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/README.threads b/README.threads index 4d20243ce7..014eed833a 100644 --- a/README.threads +++ b/README.threads @@ -155,15 +155,49 @@ COND_BROADCAST work by putting back all the threads on the condition variables list into the run queue. Note that a mutex must *not* be held while returning from a PP function. -Perl locks are a condpair_t structure (a triple of a mutex, a -condtion variable and an owner thread field) attached by 'm' -magic to any SV. pp_lock locks such an object by waiting on the -condition variable until the owner field is zero and then setting -the owner field to its own thread pointer. The lock is recursive -so if the owner field already matches the current thread then -pp_lock returns straight away. If the owner field has to be filled -in then unlock_condpair is queued as an end-of-block destructor and -that function zeroes out the owner field, releasing the lock. +Perl locks and condition variables are both implemented as a +condpair_t structure, containing a mutex, an "owner" condition +variable, an owner thread field and another condition variable). +The structure is attached by 'm' magic to any SV. pp_lock locks +such an object by waiting on the ownercond condition variable until +the owner field is zero and then setting the owner field to its own +thread pointer. The lock is semantically recursive so if the owner +field already matches the current thread then pp_lock returns +straight away. If the owner field has to be filled in then +unlock_condpair is queued as an end-of-block destructor and +that function zeroes out the owner field and signals the ownercond +condition variable, thus waking up any other thread that wants to +lock it. When used as a condition variable, the condpair is locked +(involving the above wait-for-ownership and setting the owner field) +and the spare condition variable field is used for waiting on. + + +Thread states + + + $t->join +R_JOINABLE ---------------------> R_JOINED >----\ + | \ pthread_join(t) | ^ | + | \ | | join | pthread_join + | \ | | | + | \ | \------/ + | \ | + | \ | + | $t->detach\ pthread_detach | + | _\| | +ends| R_DETACHED ends | unlink + | \ | + | ends \ unlink | + | \ | + | \ | + | \ | + | \ | + | \ | + V join detach _\| V +ZOMBIE ----------------------------> DEAD + pthread_join pthread_detach + and unlink and unlink + Malcolm Beattie |