summaryrefslogtreecommitdiffstats
path: root/Demo/threads/sync.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-10-08 19:07:57 (GMT)
committerGuido van Rossum <guido@python.org>1994-10-08 19:07:57 (GMT)
commit6910f42d231b290c43c5249c6bd27497d25f0aa8 (patch)
tree214f50091274b30290b8883763054520f11511fa /Demo/threads/sync.py
parent81a12bceb66addd44236b1321434ead622a1de88 (diff)
downloadcpython-6910f42d231b290c43c5249c6bd27497d25f0aa8.zip
cpython-6910f42d231b290c43c5249c6bd27497d25f0aa8.tar.gz
cpython-6910f42d231b290c43c5249c6bd27497d25f0aa8.tar.bz2
new version by Tim
Diffstat (limited to 'Demo/threads/sync.py')
-rw-r--r--Demo/threads/sync.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Demo/threads/sync.py b/Demo/threads/sync.py
index 6cdf3e8..3044724 100644
--- a/Demo/threads/sync.py
+++ b/Demo/threads/sync.py
@@ -258,6 +258,15 @@
# writing. Then if some other thread is waiting to write, it's
# allowed to proceed. Else all threads (if any) waiting to read are
# allowed to proceed.
+#
+# .write_to_read()
+# Use instead of a .write_in to declare that the thread is done
+# writing but wants to continue reading without other writers
+# intervening. If there are other threads waiting to write, they
+# are allowed to proceed only if the current thread calls
+# .read_out; threads waiting to read are only allowed to proceed
+# if there are are no threads waiting to write. (This is a
+# weakness of the interface!)
import thread
@@ -464,6 +473,18 @@ class mrsw:
self.readOK.broadcast()
self.rwOK.release()
+ def write_to_read(self):
+ self.rwOK.acquire()
+ if not self.writing:
+ raise ValueError, \
+ '.write_to_read() invoked without an active writer'
+ self.writing = 0
+ self.nw = self.nw - 1
+ self.nr = self.nr + 1
+ if not self.nw:
+ self.readOK.broadcast()
+ self.rwOK.release()
+
# The rest of the file is a test case, that runs a number of parallelized
# quicksorts in parallel. If it works, you'll get about 600 lines of
# tracing output, with a line like