[C++-sig] X-language polymorphism and multithreading
Hans Meine
hans_meine at gmx.net
Tue Jul 6 16:11:28 CEST 2010
On Saturday 03 July 2010 03:03:53 Anton Yabchinskiy wrote:
> So, I need PyGILState_Ensure/PyGILState_Release around the
> overridden method call, and PyEval_InitThreads in the module
> initialization. Am I right? Is the following code OK?
The code looks OK to me at least, but what's your problem? (You just wrote
"does not work"!) Is there still a problem with the code below?
If so, I can see potential problems just due to ownership handling, for
example you pass &data to the callbacks, but who's the owner of that data? Is
it possible that another thread releases the memory while the callback is
running?
Oh, I see another likely problematic thing:
> void
> on_data(const Data_Buffer& data)
> {
> if (override on_data = get_override("on_data")) {
> GIL_State_Guard guard;
>
> on_data(data);
> }
> default_on_data(data);
> }
You're calling get_override - although I never used it, I believe it performs
some PyObject_GetAttr or similar to check for an overridden method. Remember:
As soon as you're dealing with any python objects, you need the GIL! (A
common problem is that people don't see _GetItem oder _GetAttr as "running
python code", although that's pushing your luck!)
HTH,
Hans
More information about the Cplusplus-sig
mailing list