Add a delay before releasing the lock

To avoid when the lock gets released and the
time to acquire is below the float tolerance
add-on a sleep to ensure that there is always
some variation in timing before the acquisition
by another thread.

If the cause of this bug is a time shift (ntpd?)
then this will not be a fix (a fix for that is
only available in py3.3).

Fixes bug 1288521

Change-Id: I3294e81ce043a2c91730bb614020bb79c867dcdb
This commit is contained in:
Joshua Harlow
2014-03-05 18:49:41 -08:00
parent 0102c34d83
commit 2b875590cf

View File

@@ -23,6 +23,11 @@ from concurrent import futures
from taskflow import test
from taskflow.utils import lock_utils
# NOTE(harlowja): Sleep a little so time.time() can not be the same (which will
# cause false positives when our overlap detection code runs). If there are
# real overlaps then they will still exist.
NAPPY_TIME = 0.05
def _find_overlaps(times, start, end):
overlaps = 0
@@ -39,10 +44,12 @@ def _spawn_variation(readers, writers, max_workers=None):
def read_func():
with lock.read_lock():
start_stops.append(('r', time.time(), time.time()))
time.sleep(NAPPY_TIME)
def write_func():
with lock.write_lock():
start_stops.append(('w', time.time(), time.time()))
time.sleep(NAPPY_TIME)
if max_workers is None:
max_workers = max(0, readers) + max(0, writers)