title: Passing multiprocessing.Value object into a ctype function?
body: <p>I am working with a python function that gets a Value object from python's multiprocessing library passed into it and needs to use a ctype function to modify it. The issue is that I can't find a good way and I'm not sure if it's possible to pass the Value object into the ctype function such that the value will be modified.</p>
  
  <p>My python code looks like this:</p>
  
  <pre><code>#main.py
  import ctypes, glob
  from multiprocessing import Value
  
  libfile = glob.glob('build/*/mod_func*.so')[0]
  mylib = ctypes.CDLL(libfile)
  
  test_value = Value("i", -99)
  mylib.mod_func.argtypes = [ctypes.c_int]
  
  print(test_value.value)
  mylib.mod_func(test_value.value)
  print(test_value.value)
  </code></pre>
  
  <p>And the C++ code I am buliding looks like this:</p>
  
  <pre><code>//testcode.cpp
  extern "C"
  void mod_func(int &amp;val)
  {
     val = 10;
  }
  </code></pre>
  
  <p>I built the C++ code with the command <code>python setup.py build</code>, where setup.py is as follows:</p>
  
  <pre><code>from setuptools import setup, Extension
  setup(
     ext_modules=[Extension('mod_func', ['testcode.cpp'],),],
  )
  </code></pre>
  
  <p>When I run <code>main.py</code>,  the output I get is:</p>
  
  <pre><code>-99
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>The error is probably caused by me trying to pass <code>Value.value</code> to my ctype function, but I'm not sure what else I can do. I can't just use the value returned by the ctype function, because my main python code is going to be run in a Thread and forcibly terminated at some point before the ctype function finishes executing, so I want to iteratively update a value passed into the ctype function that can be viewed when the thread is terminated.</p>
  
  <p>Any ideas?</p>