On 05/02/2016 at 02:06, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R17
Platform: Windows ;
Language(s) : C++ ;
---------
I've hit some problems on R17 with using TestBreak from thread that was not created via C4DThread. I am trying to achieve something like this:
// Threaded callback function executed from thirdparty library
void threadedCallback(BaseThread* originalThread)
{
...
if (originalThread->TestBreak()) return;
...
}
// Function executed inside C4D thread
void foo(BaseThread* thread, ...)
{
// Call (blocking) multithreaded function of thirdparty library
thirdparty_class->processData(threadedCallback, thread);
}
Here _thirdparty_class- >processData() _is implemented in thirdparty library (that I have no control over implementation) and it starts several new threads, each will eventually call threadedCallback(). Now because threadedCallback() takes quite long time to finish, I need to check for user interruption of original C4D thread. Unfortunatelly, calling TestBreak crashes C4D (note that this worked before R17).
I can guess this is because C4D tries to find some info about calling thread in its internal structures and it crashes because it did not created calling thread. Am I correct with this assumption? If so, is there some reasonable way how to solve this?
Note that currently I am solving this by using extra bool flag that I set from C4D thread and check in threadedCallback, ie:
volatile bool break_flag;
// Threaded callback function executed from thirdparty library
void threadedCallback(BaseThread* originalThread)
{
...
if (break_flag) return;
...
}
// Function executed inside C4D thread
void foo(BaseThread* thread, ...)
{
break_flag = false;
// Call (non-blocking) multithreaded function of thirdparty library
thirdparty_class->processDataNonBlocking(threadedCallback, thread);
while (thirdparty_class->isRunning())
{
if (thread->TestBreak()) break_flag = true;
GeSleep(100);
}
}
Obviously this is not good solution, so I would like to find a way without active waiting...