title: Using function pointers to methods of classes without the gil
body: <p>Part of my works requires a lot of calculations, but they are often fairly straight-forward and can in principle quite easily be done in parallel with Cython's prange, requiring nogil. However, given that I tried to write my Cython code with a focus on having cdef classes as building blocks I encountered a problem.</p>
  
  <p>Let's say I got an numerical integration routine or similar which takes a function pointer as an input</p>
  
  <pre><code>ctypedef double (* someFunctionPointer) (double tt) nogil
  
  cdef double integrationRoutine(someFunctionfointer ff) nogil:
      # Doing something
      # ...
      return result
  </code></pre>
  
  <p>Now each of my integration points is actually a "larger" simulation (lots of parameters and so on I load/set/input or whatever), which is implemented in a class. So my initial approach was doing something like</p>
  
  <pre><code>cdef class SimulationClass:
  
      cdef double simulationFunctionPointer(SimulationClass self, double tt) nogil:
          # ...
  </code></pre>
  
  <p>where I though I could just hand "simulationFunctionPointer" to "integrationRoutine" and would be fine. This does of course not work because of the self argument.</p>
  
  <p>All my work-arounds either require to</p>
  
  <ul>
  <li>Not use cdef classes, rather something like a C struct (tricky if SimulationClass references a lot of other classes, parameters and so on)</li>
  <li>Execute something with gil (because I want to work the SimulationClass; I wrote some stand alone function which took SimulationClass as a void*, but then I need to cast it to SimulationClass again, which requires the gil)</li>
  </ul>
  
  <p>Any advice or ideas how to approach this problem? Is my first approach possible in other languages like C++?</p>
  
  <p>Cheers</p>