On 06/14/2016 12:28 PM, Julian Taylor wrote:
On 14.06.2016 19:34, Burlen Loring wrote:


here's my question: given Py_BEGIN_ALLOW_THREADS is used by numpy how
can numpy be thread safe? and how can someone using the C-API know where
it's necessary to acquire the GIL? Maybe someone can explain this?


numpy only releases the GIL when it is not accessing any python objects or other non-threadsafe structures anymore.
That is usually during computation loops and IO.


Your problem is indeed a missing PyGILState_Ensure

I am assuming that the threads you are using are not created by python, so you don't have a threadstate setup and no GIL. You do set it up with that function, see https://docs.python.org/2/c-api/init.html#non-python-created-threads
I'm already hold the GIL in each thread via the mechanism you pointed to, and I have verified this with gdb, some how GIL is being released. re-acquiring the GIL solves the issue, but it technically should cause a deadlock to acquire 2x in the same thread. I suspect Numpy use of Py_BEGIN_ALLOW_THREADS is cause of the issue. It will take some work to verify.
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to