blueloveTH 2 éve
szülő
commit
d53cd8e956
2 módosított fájl, 5 hozzáadás és 5 törlés
  1. 4 0
      examples/abort-the-vm/main.cpp
  2. 1 5
      examples/abort-the-vm/user_config.h

+ 4 - 0
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<bool> _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;
 }

+ 1 - 5
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