Hi guys!<br><br>I am trying to build a C++ application that uses pthreads and embedded python. I've simplified the problem down so that the Python code is a single class that subclasses from Queue. The main thread of the C++ application adds to the queue. A worker thread in the C++ application reads from the queue.<br>

<br>I am using:<br>PyGILState_Ensure()<br>PyGILState_Release()<br><br>to lock the GIL and release it.<br><br>I'm finding this situation happening:<br>1) main thread locks the GIL<br>2) worker thread locks the GIL<br>
3) main thread tries to release the GIL, but the thread state is not current and the program aborts with this error:<br>Fatal Python error: This thread state must be current when releasing<br><br>Other times, the program runs to completion, only to segfault just before it exits.<br>
<br>C++ code can be found here:<br><a href="http://pastie.org/2035072">http://pastie.org/2035072</a><br><br>Python code can be found here:<br><a href="http://pastie.org/2035086">http://pastie.org/2035086</a><br><br><br>I've tried several different APIs without any success. This is my first attempt at embedding Python. So, what is correct way to do this?<br>
<br>Any suggestions will be appreciated.<br><br>Thanks!<br>Tom<br>