New submission from Tim Peters:

I'm sure this flaw exists on more than just the current default branch, but 
didn't check.

BoundedSemaphore.release() doesn't quite do what it thinks it's doing.  By 
eyeball, the code obviously suffers from a small timing hole:  multiple threads 
releasing at the same time can all see "self._value >= self._initial_value" as 
false before any of them actually releases the semaphore.  So the value of 
._value can become arbitrarily higher than ._initial_value.

This is hard to provoke.  The attached patch adds a TESTWAIT Event to 
BoundedSemaphore so that the new file (unbounded.py) can demonstrate the race 
reliably.  The patch doesn't fix anything - it's just a way to demonstrate the 
problem.  At the end, unbounded.py prints

bs._value is 2

That should be "impossible" for a BoundedSemaphore(1).

----------
components: Library (Lib)
files: sema
messages: 198928
nosy: tim.peters
priority: normal
severity: normal
stage: needs patch
status: open
title: BoundedSemaphore.release() subject to races
type: behavior
versions: Python 3.5
Added file: http://bugs.python.org/file31957/sema

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19158>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to