Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your problem, you have a C++ program that calls into python. When python finishes executing a function, you want to pause the interpreter and pick up where the C++ code left off. Some time later your C++ program needs to cal back into python, and have the python interpreter pick up where it left off.</p> <p>I don't think you can do this very easily with one thread. Before you pause the interpreter the stack looks like this:</p> <pre><code>[ top of stack ] [ some interpreter frames ] [ some c++ frames ] </code></pre> <p>To pause the interpreter, you need to save off the interpreter frames, and jump back to the top-most C++ frame. Then to unpause, you need to restore the interpreter frames, and jump up the stack to where you left off. Jumping is doable (see <a href="http://en.wikipedia.org/wiki/Setjmp.h" rel="nofollow">http://en.wikipedia.org/wiki/Setjmp.h</a>), but saving and restoring the stack is harder. I don't know of an API to do this.</p> <p>However you could do this with two threads. The thread created at the start of your c++ program (call it thread 1) runs the c++ code, and it creates thread 2 to run the python interpreter.</p> <p>Initially (when were running c++ code), thread 1 is executing and thread 2 is blocked (say on a condition variable, see <a href="https://computing.llnl.gov/tutorials/pthreads/" rel="nofollow">https://computing.llnl.gov/tutorials/pthreads/</a>). When you run or unpause the interpreter thread 1 signals the condition variable, and waits on it. This wakes up thread 2 (which runs the interpreter) and causes thread 1 to block. When the interpreter needs to pause, thread 2 signals the condition variable and waits on it (so thread 2 blocks, thread 1 wakes up). You can bounce back and forth between the threads to your heart's content. Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload