Exemple #1
0
 def test_read_block_interrupt_schedule(self):
     """Test read block interrupt then schedule on rw_lock."""
     lock = coro.rw_lock()
     lock.write_lock()
     self._resume_count = 0
     threads = []
     # Spawn some threads that will block and be interrupted.
     for unused in xrange(5):
         threads.append(coro.spawn(self._read_block, lock))
     # Spawn a thread that we will not interrupt.
     no_interrupt_thread = coro.spawn(self._read_block, lock)
     coro.yield_slice()
     # Cause an interrupt on these threads.
     for t in threads:
         t.shutdown()
     # Now try to get the non-interrupted thread to run.
     lock.write_unlock()
     coro.yield_slice()
     # Verify that it ran.
     self.assertEqual(self._resume_count, 1)
Exemple #2
0
 def test_write_block_schedule_interrupt(self):
     """Test write block schedule then interrupt on rw_lock."""
     lock = coro.rw_lock()
     lock.read_lock()
     self._resume_count = 0
     threads = []
     # Spawn some threads that will block and be interrupted.
     for unused in xrange(5):
         threads.append(coro.spawn(self._write_block, lock))
     # Spawn a thread that we will not interrupt.
     no_interrupt_thread = coro.spawn(self._write_block, lock)
     coro.yield_slice()
     # Schedule all of the threads.
     lock.read_unlock()
     # Now interrupt them.
     for t in threads:
         t.shutdown()
     coro.yield_slice()
     # Verify that it ran.
     self.assertEqual(self._resume_count, 1)
Exemple #3
0
 def test_read_block_interrupt_schedule(self):
     """Test read block interrupt then schedule on rw_lock."""
     lock = coro.rw_lock()
     lock.write_lock()
     self._resume_count = 0
     threads = []
     # Spawn some threads that will block and be interrupted.
     for unused in xrange(5):
         threads.append(coro.spawn(self._read_block, lock))
     # Spawn a thread that we will not interrupt.
     no_interrupt_thread = coro.spawn(self._read_block, lock)
     coro.yield_slice()
     # Cause an interrupt on these threads.
     for t in threads:
         t.shutdown()
     # Now try to get the non-interrupted thread to run.
     lock.write_unlock()
     coro.yield_slice()
     # Verify that it ran.
     self.assertEqual(self._resume_count, 1)
Exemple #4
0
 def test_write_block_schedule_interrupt(self):
     """Test write block schedule then interrupt on rw_lock."""
     lock = coro.rw_lock()
     lock.read_lock()
     self._resume_count = 0
     threads = []
     # Spawn some threads that will block and be interrupted.
     for unused in xrange(5):
         threads.append(coro.spawn(self._write_block, lock))
     # Spawn a thread that we will not interrupt.
     no_interrupt_thread = coro.spawn(self._write_block, lock)
     coro.yield_slice()
     # Schedule all of the threads.
     lock.read_unlock()
     # Now interrupt them.
     for t in threads:
         t.shutdown()
     coro.yield_slice()
     # Verify that it ran.
     self.assertEqual(self._resume_count, 1)
Exemple #5
0
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import coro

rw_lock = coro.rw_lock()


def test_rw_lock():
    rw_lock.read_lock()
    rw_lock.read_lock()
    # since write_lock will block, let's get someone to unlock the readers
    coro.spawn(unlocker)
    rw_lock.write_lock()
    coro.spawn(reader)
    coro.spawn(writer)
    coro.yield_and_schedule()
    rw_lock.write_unlock()
    coro._exit = 1

Exemple #6
0
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import coro

rw_lock = coro.rw_lock()

def test_rw_lock():
    rw_lock.read_lock()
    rw_lock.read_lock()
    # since write_lock will block, let's get someone to unlock the readers
    coro.spawn(unlocker)
    rw_lock.write_lock()
    coro.spawn(reader)
    coro.spawn(writer)
    coro.yield_and_schedule()
    rw_lock.write_unlock()
    coro._exit = 1

def writer():
    rw_lock.write_lock()