/* worker_thread.c */
result = doDangerousThing(); // this could kill the thread
putToLocklessQueue(result, *queue_in_main_thread);
/* main_thread.c */
if (hasItems(my_lockless_queue)) {
PyGILState_Ensure();
while (hasItems(my_lockless_queue)) {
storeToPythonObject(popItem(my_lockless_queue));
}
PyGILState_Release();
// sleep again here
}
我不完全确定如何终止线程,但在我头脑中的实现中,你会破坏线程对象,不是吗?在这种情况下,你释放了析构函数中的锁。。。在
我建议改变线程之间的交互模式。在
您当前的实现方式如下:
变体A,明显:
^{pr2}$变型B,不太明显,见[1],[2]了解想法:
相关问题 更多 >
编程相关推荐