Author: Remi Meier <[email protected]>
Branch: nogil-unsafe-2
Changeset: r90448:8343a9230861
Date: 2017-03-01 19:22 +0100
http://bitbucket.org/pypy/pypy/changeset/8343a9230861/

Log:    (arigo, remi) disable non-__thread threadlocals

        Building the threadlocals (memset to 0) overwrites an acquired
        GIL...

diff --git a/rpython/memory/gctransform/shadowstack.py 
b/rpython/memory/gctransform/shadowstack.py
--- a/rpython/memory/gctransform/shadowstack.py
+++ b/rpython/memory/gctransform/shadowstack.py
@@ -231,7 +231,7 @@
 
         def thread_setup():
             allocate_shadow_stack()
-            tl_synclock.setraw(1)  # acquire "gil"
+            tl_synclock.get_or_make_raw()  # reference the field at least once
 
         def thread_run():
             # If it's the first time we see this thread, allocate
diff --git a/rpython/translator/c/src/threadlocal.c 
b/rpython/translator/c/src/threadlocal.c
--- a/rpython/translator/c/src/threadlocal.c
+++ b/rpython/translator/c/src/threadlocal.c
@@ -101,7 +101,7 @@
 {
     struct pypy_threadlocal_s *tls = (struct pypy_threadlocal_s *)p;
     struct pypy_threadlocal_s *oldnext;
-    memset(p, 0, sizeof(struct pypy_threadlocal_s));
+    // XXX: memset(p, 0, sizeof(struct pypy_threadlocal_s));
 
 #ifdef RPY_TLOFS_p_errno
     tls->p_errno = &errno;
diff --git a/rpython/translator/c/src/threadlocal.h 
b/rpython/translator/c/src/threadlocal.h
--- a/rpython/translator/c/src/threadlocal.h
+++ b/rpython/translator/c/src/threadlocal.h
@@ -37,7 +37,7 @@
 
 
 /* ------------------------------------------------------------ */
-#ifdef USE___THREAD
+// XXX: #ifdef USE___THREAD
 /* ------------------------------------------------------------ */
 
 
@@ -71,47 +71,48 @@
 
 
 /* ------------------------------------------------------------ */
-#else
-/* ------------------------------------------------------------ */
+/* #else */
+/* /\* ------------------------------------------------------------ *\/ */
+/* # error "no." */
+/* /\* Threadlocals_build needs work *\/ */
 
+/* /\* Don't use '__thread'. *\/ */
 
-/* Don't use '__thread'. */
+/* #ifdef _WIN32 */
+/* #  include <WinSock2.h> */
+/* #  include <windows.h> */
+/* #  define _RPy_ThreadLocals_Get()   TlsGetValue(pypy_threadlocal_key) */
+/* #  define _RPy_ThreadLocals_Set(x)  TlsSetValue(pypy_threadlocal_key, x) */
+/* typedef DWORD pthread_key_t; */
+/* #else */
+/* #  include <pthread.h> */
+/* #  define _RPy_ThreadLocals_Get()   
pthread_getspecific(pypy_threadlocal_key) */
+/* #  define _RPy_ThreadLocals_Set(x)  
pthread_setspecific(pypy_threadlocal_key, x) */
+/* #endif */
 
-#ifdef _WIN32
-#  include <WinSock2.h>
-#  include <windows.h>
-#  define _RPy_ThreadLocals_Get()   TlsGetValue(pypy_threadlocal_key)
-#  define _RPy_ThreadLocals_Set(x)  TlsSetValue(pypy_threadlocal_key, x)
-typedef DWORD pthread_key_t;
-#else
-#  include <pthread.h>
-#  define _RPy_ThreadLocals_Get()   pthread_getspecific(pypy_threadlocal_key)
-#  define _RPy_ThreadLocals_Set(x)  pthread_setspecific(pypy_threadlocal_key, 
x)
-#endif
 
+/* #define OP_THREADLOCALREF_ADDR(r)               \ */
+/*     do {                                        \ */
+/*         r = (void *)_RPy_ThreadLocals_Get();    \ */
+/*         if (!r)                                 \ */
+/*             r = _RPython_ThreadLocals_Build();  \ */
+/*     } while (0) */
 
-#define OP_THREADLOCALREF_ADDR(r)               \
-    do {                                        \
-        r = (void *)_RPy_ThreadLocals_Get();    \
-        if (!r)                                 \
-            r = _RPython_ThreadLocals_Build();  \
-    } while (0)
+/* #define _OP_THREADLOCALREF_ADDR_SIGHANDLER(r)   \ */
+/*     do {                                        \ */
+/*         r = (void *)_RPy_ThreadLocals_Get();    \ */
+/*     } while (0) */
 
-#define _OP_THREADLOCALREF_ADDR_SIGHANDLER(r)   \
-    do {                                        \
-        r = (void *)_RPy_ThreadLocals_Get();    \
-    } while (0)
+/* #define RPY_THREADLOCALREF_ENSURE()             \ */
+/*     if (!_RPy_ThreadLocals_Get())               \ */
+/*         (void)_RPython_ThreadLocals_Build(); */
 
-#define RPY_THREADLOCALREF_ENSURE()             \
-    if (!_RPy_ThreadLocals_Get())               \
-        (void)_RPython_ThreadLocals_Build();
+/* #define RPY_THREADLOCALREF_GET(FIELD)           \ */
+/*     ((struct pypy_threadlocal_s *)_RPy_ThreadLocals_Get())->FIELD */
 
-#define RPY_THREADLOCALREF_GET(FIELD)           \
-    ((struct pypy_threadlocal_s *)_RPy_ThreadLocals_Get())->FIELD
 
-
-/* ------------------------------------------------------------ */
-#endif
+/* /\* ------------------------------------------------------------ *\/ */
+/* #endif */
 /* ------------------------------------------------------------ */
 
 
diff --git a/rpython/translator/c/test/test_standalone.py 
b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -1472,7 +1472,7 @@
 
         if SUPPORT__THREAD:
             runme(no__thread=False)
-        runme(no__thread=True)
+        #runme(no__thread=True)
 
 
 class TestShared(StandaloneTests):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to