Commit 5142460d authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang/thread: Add links to upstream PyThread_release_lock bug

I reported the bug (see 69db91bf "libgolang: Add internal
semaphores") to CPython and PyPy upstreams. PyPy people already fixed it
and the fix, if I understood correctly, should be available as part of
PyPy 7.2 . Let's hope that CPython 2.7 will be also fixed.

- https://bugs.python.org/issue38106
    -> https://github.com/python/cpython/pull/16047
- https://bitbucket.org/pypy/pypy/issues/3072

Added Python-level test triggers the bug with high probability.
Dedicated C-level Semaphore-only test is pending.
parent 38f1900b
......@@ -288,6 +288,22 @@ def test_chan_buf_recv_vs_tryrecv_race():
for i in range(3):
done.recv()
# send/recv on the same channel in both directions.
# this triggers https://bugs.python.org/issue38106 on MacOS.
def test_chan_sendrecv_2way():
N = 1000
ch = chan()
def _():
for i in range(N):
assert ch.recv() == ('hello %d' % i)
ch.send('world %d' % i)
go(_)
for i in range(N):
ch.send('hello %d' % i)
assert ch.recv() == ('world %d' % i)
# benchmark sync chan send/recv.
def bench_chan(b):
......
......@@ -52,19 +52,27 @@ from cpython.pythread cimport PyThread_acquire_lock, PyThread_release_lock, \
# This way when Pygolang is used with buggy Python/darwin, the bug leads to
# frequently appearing deadlocks, while e.g. CPython3/darwin works ok.
#
# -> TODO maintain our own semaphore code.
# The bug was reported to CPython/PyPy upstreams:
#
# - https://bugs.python.org/issue38106
# - https://bitbucket.org/pypy/pypy/issues/3072
#
# -> TODO maintain our own semaphore code or stop printing the warning when/if
# fixed CPython/PyPy versions are released.
import sys, platform
if 'darwin' in sys.platform:
pyimpl = platform.python_implementation()
pyver = sys.version_info
buggy = None
buggy = buglink = None
if 'CPython' in pyimpl and pyver < (3, 0):
buggy = "cpython2/darwin"
buggy = "cpython2/darwin"
buglink = "https://bugs.python.org/issue38106"
if 'PyPy' in pyimpl:
buggy = "pypy/darwin"
buggy = "pypy/darwin"
buglink = "https://bitbucket.org/pypy/pypy/issues/3072"
if buggy:
print("WARNING: pyxgo: thread: %s has race condition bug in runtime"
" that leads to deadlocks" % buggy, file=sys.stderr)
" that leads to deadlocks (%s)" % (buggy, buglink), file=sys.stderr)
# make sure python threading is initialized, so that there is no concurrent
# calls to PyThread_init_thread from e.g. PyThread_allocate_lock later.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment