mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
new version by Tim
This commit is contained in:
parent
81a12bceb6
commit
6910f42d23
2 changed files with 496 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue