annotate Doc/lib/libmutex.tex @ 21467:4e35fa5d5708 legacy-trunk

Add documentation for the help() built-in; contributed by Ka-Ping Yee. This is part of SF patch #494622.
author Fred Drake <fdrake@acm.org>
date Tue, 18 Dec 2001 16:31:08 +0000
parents 5d6fb7ff68c7
children 73d145bfd8e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11067
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 \section{\module{mutex} ---
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2 Mutual exclusion support}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 \declaremodule{standard}{mutex}
15467
d7864345b1c8 Update Moshe Zadka's email address to one works and might last a while.
Fred Drake <fdrake@acm.org>
parents: 13625
diff changeset
5 \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
11067
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 \modulesynopsis{Lock and queue for mutual exclusion.}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7
15774
5d6fb7ff68c7 Added missing word; fixed minor nits.
Fred Drake <fdrake@acm.org>
parents: 15467
diff changeset
8 The \module{mutex} module defines a class that allows mutual-exclusion
13625
fdfd1049f36e Rob W. W. Hooft's spelling fixes for the Library Reference. I hope
Thomas Wouters <thomas@python.org>
parents: 11070
diff changeset
9 via acquiring and releasing locks. It does not require (or imply)
11070
0dd50a70c47e Moshe: Remove extraneous "and".
Fred Drake <fdrake@acm.org>
parents: 11067
diff changeset
10 threading or multi-tasking, though it could be useful for
11067
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 those purposes.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 The \module{mutex} module defines the following class:
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15 \begin{classdesc}{mutex}{}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 Create a new (unlocked) mutex.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 A mutex has two pieces of state --- a ``locked'' bit and a queue.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 When the mutex is not locked, the queue is empty.
15774
5d6fb7ff68c7 Added missing word; fixed minor nits.
Fred Drake <fdrake@acm.org>
parents: 15467
diff changeset
20 Otherwise, the queue contains zero or more
11067
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 \code{(\var{function}, \var{argument})} pairs
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 representing functions (or methods) waiting to acquire the lock.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23 When the mutex is unlocked while the queue is not empty,
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 the first queue entry is removed and its
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 \code{\var{function}(\var{argument})} pair called,
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 implying it now has the lock.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 Of course, no multi-threading is implied -- hence the funny interface
15774
5d6fb7ff68c7 Added missing word; fixed minor nits.
Fred Drake <fdrake@acm.org>
parents: 15467
diff changeset
29 for \method{lock()}, where a function is called once the lock is
5d6fb7ff68c7 Added missing word; fixed minor nits.
Fred Drake <fdrake@acm.org>
parents: 15467
diff changeset
30 acquired.
11067
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 \end{classdesc}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 \subsection{Mutex Objects \label{mutex-objects}}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 \class{mutex} objects have following methods:
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38 \begin{methoddesc}{test}{}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 Check whether the mutex is locked.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 \end{methoddesc}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 \begin{methoddesc}{testandset}{}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 ``Atomic'' test-and-set, grab the lock if it is not set,
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 and return true, otherwise, return false.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 \end{methoddesc}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 \begin{methoddesc}{lock}{function, argument}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 Execute \code{\var{function}(\var{argument})}, unless the mutex is locked.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 In the case it is locked, place the function and argument on the queue.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 See \method{unlock} for explanation of when
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 \code{\var{function}(\var{argument})} is executed in that case.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52 \end{methoddesc}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54 \begin{methoddesc}{unlock}{}
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55 Unlock the mutex if queue is empty, otherwise execute the first element
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56 in the queue.
dfb5add684c3 Mutex documentation from Moshe.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 \end{methoddesc}