On 29/05/2014 at 04:58, xxxxxxxx wrote:
Sorry, TestDBreak seems to be triggered only once before the MP threads start.
It is not triggered when the MP threads are running.
It does not matter if I put it in the control thread or the MP thread?
Small update:
If I put TestDBreak in the MP thread (like below) it is never triggered.
If I put TestDBreak in the control thread it is triggered only once.
// example code for a menu plugin and multiprocessing
#include "c4d.h"
#include "c4d_symbols.h"
#include "c4d_memory_mp.h"
#define ID_PIM 123112 //test plugin id
Bool escape_pressed()
{
BaseContainer bc;
Bool rs = GetInputState(BFM_INPUT_KEYBOARD, KEY_ESC, bc);
if (rs && bc.GetInt32(BFM_INPUT_VALUE))
{
MessageDialog("Stopped by user.");
GePrint("Stopped by user.");
return true;
}
return false;
} // end escape_pressed
class MPTest : public C4DThread
{
public:
Random rnd;
Int32 start;
Float result;
Float duration;
virtual void Main(void);
virtual const Char* GetThreadName(void) { return "SDK MpTest"; }
virtual Bool TestDBreak(void);
};
Bool MPTest::TestDBreak(void)
{
GePrint("MPTest::TestDBreak: esc? " + escape_pressed());
return true;
}
void MPTest::Main(void)
{
// ... See example
}
class ControlThread : public C4DThread
{
public:
virtual void Main(void);
virtual const Char* GetThreadName(void) { return "SDK ControlThread"; }
//virtual Bool TestDBreak(void);
};
//Bool ControlThread::TestDBreak(void)
//{
// GePrint("ControlThread::TestDBreak: esc? " + escape_pressed());
// return true;
//}
void ControlThread::Main(void)
{
GeShowMouse(MOUSE_BUSY);
MPThreadPool mp;
Int32 i, cnt = GeGetCPUCount();
GePrint("Nr of processors / cores: " + String::IntToString(cnt));
if (cnt == 0)
return;
MPAlloc<MPTest> thread;
AutoGeFree<C4DThread*> list = NewMemClear(C4DThread *, cnt);
if (!list || !thread.Init(cnt))
return;
for (i = 0; i < cnt; i++)
{
thread[i].start = i;
thread[i].result = 0.0;
list[i] = &thread[i];
}
if (!mp.Init(*this, cnt, list))
return;
Float64 start_time = GeGetMilliSeconds();
if (!mp.Start(THREADPRIORITY_BELOW))
return;
Float64 start_duration = GeGetMilliSeconds() - start_time;
mp.Wait();
//... set string See example
GeShowMouse(MOUSE_NORMAL);
MessageDialog(str);
}
class MenuTest : public CommandData
{
public:
virtual Bool Execute(BaseDocument* doc);
};
Bool MenuTest::Execute(BaseDocument* doc)
{
ControlThread ct;
return ct.Start(THREADMODE_SYNCHRONOUS); // multiprocessing test
}
Bool RegisterMyPlugin(void)
{
// ...
}