About threads
-
Hello
The around thread becomes new from R20 and it does not work with the old code.
I am trying while looking at the SDK sample, but it does not move with an error.No 1 error
An operator that handles the right operand of maxon :: ResultMemT <maxon :: BaseRef <IMPLEMENTATION, maxon :: StrongRefHandler >> 'can not be found (or can not be converted).class MyThread : public maxon::ThreadInterfaceTemplate<MyThread>
{
public:
const char* GetName() const { return "MyThread"; }
maxon::Result<void> operator ()()
{
GePrint("ok"_s);
}
};class MenuTest : public CommandData
{
static maxon::ThreadRefTemplate<MyThread> g_test;
public:
virtual Bool Execute(BaseDocument doc);
};Bool MenuTest::Execute(BaseDocument doc)
{
if (!g_test) g_test = MyThread::Create() iferr_return; // No1 Error
}Please tell me if you can understand.
-
Hello,
there are a few issues with the code you posted.
First, please make sure to use the correct function declarations.
CommandData::Execute()
is defined asExecute(BaseDocument* doc)
The
doc
argument is a pointer, not a copy.Second, please pay attention to return values. The
Execute()
function must return a Bool value. Theoperator()()
of the thread must return amaxon::Result<void>
.In the
Execute()
function you create a thread instance. You must handle the error object returned by theCreate()
function.There are multiple ways to handle such error values. You find examples in the Error Handling manual.
One way would be to use
iferr_scope_handler
. With that theExecute()
function can look like this:Bool MenuTest::Execute(BaseDocument* doc) { iferr_scope_handler { err.DiagOutput(); err.DbgStop(); return true; }; if (!g_test) { g_test = MyThread::Create() iferr_return; } return true; }
The worker function (
operator()()
) of the thread must return aResult<void>
object. This is typicallymaxon::OK
when everything is OK. You find an example of such a custom thread in the Threads Manual.Some more hints:
- for new code please use
ApplicationOutput()
instead ofGePrint()
. See API Transition. - when posting code please use the Markdown syntax. See also Markdown summary.
best wishes,
Sebastian - for new code please use
-
Hi.
Thank you for teaching me.
I am not sure of the new maxon API Threading.
Are there samples of jobs and Threads? -
Hello,
you find information and examples on jobs and threads in these manuals:
best wishes,
Sebastian