title: Node JS Native Modules: Can You Run C/C++ Methods In A Separate Libuv/NodeJS Style Process?
body: <p>A bit of a strange one this...</p>
  
  <p>I've written a NodeJS native module that works well most of the time, but the class contains a method that breaks the module when it's run in a context that shares memory. </p>
  
  <p>Roughly speaking, the module opens an IO server, but there's a bug that requires me to open and close the IO server to retrieve a particular value... When I perform this action, any pointers found to reference old IO server object obviously break/segfault (a 'scribble space' error, right?). </p>
  
  <p>To work around this problem, I currently use NodeJS's child_process.fork() to run the errant method in an isolated context, and pass messages between the main process and the forked process to have the program run as required (i.e. I call the method inside the forked process, and use 'process.on("message", ...)' to retrive the result). This works well, but it feels like a very expensive hack...</p>
  
  <p>For the record, I've tried using a Libuv thread to run the method, but I encounter the same problem. I'm guessing that's because the function call is still made in shared memory.</p>
  
  <p>Is there anyway for me to run a small portion (or more...) of C/C++ code in a 'NodeJS style' process using C++?</p>