Are there any common pitfalls with widgets usage ('update()' routine call) in multithreaded app?
I've got worker thread which executes arbitrary pieces of code and main static thread. Here are some code snippets.
Worker thread has its event loop and a timer object which fires function:
void ThreadWorker::check_new_jobs()
{
/// locking mutex, will check queue
mutex.lock ();
while (!m_queue.isEmpty())
{
IJob* job = m_queue.dequeue();
mutex.unlock(); ///< will now do the job, unlock
(*job)();
delete job;
/// lock, will check queue again
mutex.lock ();
}
/// we've finished, unlock
mutex.unlock ();
}
void ThreadWorker::check_new_jobs()
{
/// locking mutex, will check queue
mutex.lock ();
while (!m_queue.isEmpty())
{
IJob* job = m_queue.dequeue();
mutex.unlock(); ///< will now do the job, unlock
(*job)();
delete job;
/// lock, will check queue again
mutex.lock ();
}
/// we've finished, unlock
mutex.unlock ();
}
To copy to clipboard, switch view to plain text mode
And somewhere in my app:
// update rcom parameter
auto f = [=]()
{
app_set ().parameters_num ().updateObject (r06_TRIPNUM);
ts::ParameterNum p;
app_set ().parameters_num ().getObject (r06_TRIPNUM, p);
p.val.val += 1;
app_set ().parameters_num ().setObject (r06_TRIPNUM, p);
};
LambdaJob* job = new LambdaJob(f);
app_set ().worker_thread ().add_job (job);
// update rcom parameter
auto f = [=]()
{
app_set ().parameters_num ().updateObject (r06_TRIPNUM);
ts::ParameterNum p;
app_set ().parameters_num ().getObject (r06_TRIPNUM, p);
p.val.val += 1;
app_set ().parameters_num ().setObject (r06_TRIPNUM, p);
};
LambdaJob* job = new LambdaJob(f);
app_set ().worker_thread ().add_job (job);
To copy to clipboard, switch view to plain text mode
I have to understand the reason of freezes and then find erroneous piece of code
Bookmarks