[C++-sig] Thread safety (original) (raw)
dueymk dueymk at everestkc.net
Mon Dec 19 23:58:05 CET 2005
- Previous message: [C++-sig] Thread safety
- Next message: [C++-sig] Can't call injected method taking SmartPtr with derived object...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
It turns out that using the PyGILState* functions was sufficient. I also had to add:
#ifdef WITH_THREAD Py_Initialize(); PyEval_InitThreads(); #endif
to my module initialization code. After that, it seems to work fine.
Jim
Patrick Hartling wrote:
On 12/16/05, dueymk <dueymk at everestkc.net> wrote:
I have a very similar case with my use of Boost.Python. With my code, a Python object will be instantiated and then handed off to the multi-threaded C++ library. The Python interpreter runs in the primordial thread, but the method invocations on the Python object are made from a different thread. My locking of the GIL has thus far been done before the call to boost::python::getoverride() or any other Boost.Python functions. I changed my code so that the GIL is locked after the call to boost::python::getoverride() as you have done above. I found that my code crashed at the first attempt of the C++ library's attempt to invoke a method of the Python object from a spawned thread. The crash occurred as a result of the call to boost::python::getoverride() since it calls into the Python interpreter without the GIL being locked. I can provide a stack trace (from GDB) if you would like to see it. -Patrick -- Patrick L. Hartling http://www.137.org/patrick/
C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig
- Previous message: [C++-sig] Thread safety
- Next message: [C++-sig] Can't call injected method taking SmartPtr with derived object...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]