[pypy-commit] pypy py3.5: (arigo, plan_rich) remove thread local reference and keep alive the sentinel lock in the execution context
plan_rich
pypy.commits at gmail.com
Thu Oct 13 05:48:58 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5
Changeset: r87746:345a0c5b30ea
Date: 2016-10-13 11:45 +0200
http://bitbucket.org/pypy/pypy/changeset/345a0c5b30ea/
Log: (arigo, plan_rich) remove thread local reference and keep alive the
sentinel lock in the execution context
diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py
--- a/pypy/module/thread/os_local.py
+++ b/pypy/module/thread/os_local.py
@@ -13,6 +13,7 @@
ExecutionContext._thread_local_objs = None
+ExecutionContext._sentinel_lock = None
class Local(W_Root):
@@ -90,6 +91,10 @@
)
def thread_is_stopping(ec):
+ sentinel_lock = ec._sentinel_lock
+ if sentinel_lock is not None:
+ if sentinel_lock.descr_lock_locked(ec.space):
+ sentinel_lock.descr_lock_release(ec.space)
tlobjs = ec._thread_local_objs
if tlobjs is None:
return
diff --git a/pypy/module/thread/os_lock.py b/pypy/module/thread/os_lock.py
--- a/pypy/module/thread/os_lock.py
+++ b/pypy/module/thread/os_lock.py
@@ -11,7 +11,6 @@
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.interpreter.error import oefmt
from rpython.rlib.rarithmetic import r_longlong, ovfcheck, ovfcheck_float_to_longlong
-from rpython.rlib.rthread import ThreadLocalReference
# Force the declaration of the type 'thread.LockType' for RPython
#import pypy.module.thread.rpython.exttable
@@ -147,8 +146,6 @@
See LockType.__doc__ for information about locks."""
return space.wrap(Lock(space))
-tlref_sentinel_lock = ThreadLocalReference(Lock)
-
def _set_sentinel(space):
"""_set_sentinel() -> lock
@@ -158,12 +155,11 @@
This is a private API for the threading module."""
# see issue 18808. We need to release this lock just before exiting
# the any thread!
- lock = Lock(space)
- # create a weak reference to the lock object and set it
- # pass save it as a thread local reference
- # see os_thread.py just before gc_thread_die
- tlref_sentinel_lock.set(lock)
- #
+ ec = space.getexecutioncontext()
+ lock = ec._sentinel_lock
+ if lock is None:
+ lock = Lock(space)
+ ec._sentinel_lock = lock
return space.wrap(lock)
class W_RLock(W_Root):
diff --git a/pypy/module/thread/os_thread.py b/pypy/module/thread/os_thread.py
--- a/pypy/module/thread/os_thread.py
+++ b/pypy/module/thread/os_thread.py
@@ -7,7 +7,6 @@
from pypy.module.thread.error import wrap_thread_error
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec, Arguments
-from pypy.module.thread.os_lock import tlref_sentinel_lock
# Here are the steps performed to start a new thread:
#
@@ -103,11 +102,6 @@
os.write(STDERR, "\n")
except OSError:
pass
- # TODO move after rthread.gc_thread_die()?
- lock = tlref_sentinel_lock.get()
- if lock and lock.descr_lock_locked(space):
- lock.descr_lock_release(space)
- tlref_sentinel_lock.set(None)
#
bootstrapper.nbthreads -= 1
rthread.gc_thread_die()
More information about the pypy-commit
mailing list