Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Boost::Python and C++ : run in parallel

How do I run C++ and Boost::Python code in parallel without problems?

Eg in my game I'd want to execute Python code in parallel with C++ code; if the embedded Python interpreter's code executes a blocking loop, like while(True): pass, the C++ code would still be running and processing frames to render with its own loop.

I tried with boost::thread and std::thread but unless I joined these threads with the main thread the program would crash...

Any suggestions or examples?

like image 935
UberLambda Avatar asked Apr 08 '26 05:04

UberLambda


1 Answers

Your idea to use a second thread for the Python interpreter should just work. Make sure you use the PyGILState_Ensure/Release mechanisms everywhere you wish to run code that will invoke any Python or Boost::Python code. You have more details on this other SO thread here.

like image 61
André Anjos Avatar answered Apr 09 '26 19:04

André Anjos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!