Dead lock in python tracker
There is a dead lock condition in the python tracker implementation, in particular in the PythonTracker._switch_to_other_thread()
method.
Actually the switch is done through a single _sync
event which is not adequate for two threads possibly waiting on the same event and resetting the event at the same time.
The _switch_to_other_thread()
method does:
_sync.set() # wakup other
_sync.clear() # clear event
_sync.wait() # wait other to set
A race happens in the following execution for instance (where threads are marked T1
or T2
):
T2: _sync.wait()
T1: _sync.set()
T1: _sync.clear()
T2: _sync.set()
T2: _sync.clear()
T2: _sync.wait()
T1: _sync.wait()
After the sequence, both threads are waiting and the tracker is blocked.
Download and execute the file test-race.py in order to produce the bug.
$ python3 test-race.py
Traceback (most recent call last):
File "/home/cguillon/work/easytracker/test-race.py", line 56, in <module>
test_controller()
File "/home/cguillon/work/easytracker/test-race.py", line 48, in test_controller
assert (
AssertionError: FAILED, dead lock at i = 46 / 9999...