Kaydet (Commit) 6910f42d authored tarafından Guido van Rossum's avatar Guido van Rossum

new version by Tim

üst 81a12bce
This diff is collapsed.
...@@ -258,6 +258,15 @@ ...@@ -258,6 +258,15 @@
# writing. Then if some other thread is waiting to write, it's # 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. Else all threads (if any) waiting to read are
# allowed to proceed. # 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 import thread
...@@ -464,6 +473,18 @@ class mrsw: ...@@ -464,6 +473,18 @@ class mrsw:
self.readOK.broadcast() self.readOK.broadcast()
self.rwOK.release() 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 # 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 # quicksorts in parallel. If it works, you'll get about 600 lines of
# tracing output, with a line like # tracing output, with a line like
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment