diff --git a/examples/abort-the-vm/main.cpp b/examples/abort-the-vm/main.cpp index bb486831..2c530458 100644 --- a/examples/abort-the-vm/main.cpp +++ b/examples/abort-the-vm/main.cpp @@ -11,6 +11,7 @@ using namespace pkpy; class MyVM: public VM{ public: + // use atomic to protect the flag std::atomic _flag = false; MyVM(): VM(){ @@ -43,12 +44,15 @@ int main(){ std::cout << (need_more_lines ? "... " : ">>> "); std::string line; std::getline(std::cin, line); + vm->_flag = false; // reset the flag before each input // here I use linux signal to interrupt the vm // you can run this line in a thread for more flexibility need_more_lines = repl->input(line); } + + delete repl; delete vm; return 0; } diff --git a/examples/abort-the-vm/user_config.h b/examples/abort-the-vm/user_config.h index e136833c..7c28da6f 100644 --- a/examples/abort-the-vm/user_config.h +++ b/examples/abort-the-vm/user_config.h @@ -3,15 +3,11 @@ /*************** feature settings ***************/ // Whether to compile os-related modules or not -#ifndef PK_ENABLE_OS // can be overrided by cmake #define PK_ENABLE_OS 1 -#endif // Enable this if you are working with multi-threading (experimental) // This triggers necessary locks to make the VM thread-safe -#ifndef PK_ENABLE_THREAD // can be overrided by cmake -#define PK_ENABLE_THREAD 0 -#endif +#define PK_ENABLE_THREAD 1 // Enable this for `vm->_ceval_on_step` #define PK_ENABLE_CEVAL_CALLBACK 1