import unittest import threading import time import copy from ._rwlock import RWLock
class Writer(threading.Thread): def __init__(self, buffer_, rw_lock, init_sleep_time, sleep_time, to_write): """
@param buffer_: common buffer_ shared by the readers and writers
@type buffer_: list
@type rw_lock: L{RWLock}
@param init_sleep_time: sleep time before doing any action
@type init_sleep_time: C{float}
@param sleep_time: sleep time whilein critical section
@type sleep_time: C{float}
@param to_write: data that will be appended to the buffer """
threading.Thread.__init__(self)
self.__buffer = buffer_
self.__rw_lock = rw_lock
self.__init_sleep_time = init_sleep_time
self.__sleep_time = sleep_time
self.__to_write = to_write
self.entry_time = None """Time of entry to the critical section"""
self.exit_time = None """Time of exit from the critical section"""
class Reader(threading.Thread): def __init__(self, buffer_, rw_lock, init_sleep_time, sleep_time): """
@param buffer_: common buffer shared by the readers and writers
@type buffer_: list
@type rw_lock: L{RWLock}
@param init_sleep_time: sleep time before doing any action
@type init_sleep_time: C{float}
@param sleep_time: sleep time whilein critical section
@type sleep_time: C{float} """
threading.Thread.__init__(self)
self.__buffer = buffer_
self.__rw_lock = rw_lock
self.__init_sleep_time = init_sleep_time
self.__sleep_time = sleep_time
self.buffer_read = None """a copy of a the buffer read while in critical section"""
self.entry_time = None """Time of entry to the critical section"""
self.exit_time = None """Time of exit from the critical section"""
## The third reader should enter after the second one but it should ## exit before the second one exits ## (i.e. the readers should be in the critical section ## at the same time)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.