Home > Software engineering >  Multithreaded deadlock problem for help
Multithreaded deadlock problem for help

Time:09-16

I create a worker thread, in a worker thread set a timer timer, responsible for timing the main dialog interface according to the data list, refresh before a global mteux locked in guard_lock, avoid conflict data access, some of the main interface message in response to the data processing, so also should be locked before processing,
Now the problem is that if the news of the main interface response locked repeatedly, the program will get stuck no response, I don't know is a deadlock or what's the matter, such as locked in the double-click the message response, if repeated double-click will soon jammed in a row, or delete data in a row, before deleting locked, sometimes jammed, help to analysis what problem

CodePudding user response:

You can try this: the worker thread to get the data, filling a custom structure, then PostMessage messages to the UI thread, the UI thread received after data processing, after the completion of the processing inform worker threads execute the next operation,

Pseudo code like the following:
 UINT __cdecl ThreadProc (... ) 
{
.
MSG MSG.
while(! BExitThread & amp; & GetMessage (& amp; MSG, NULL, 0, 0, 0)
{
The switch (MSG) message)
{
Case MSG_XXX:
{
//perform calculations, filling structure data, send a custom message to inform the UI thread,
}
}
}
.
}


LRESULT OnXXXXX (WPARAM, LPARAM)//UI thread custom message handler
{
//parse the data, UI updates
PostThreadMessage (... );//notice threads to execute the next operation
}

CodePudding user response:

reference 1/f, 7-eleven's response:
you can try this: the worker thread to get the data, filling a custom structure, then PostMessage messages to the UI thread, the UI thread received after data processing, after the completion of the processing inform worker threads execute the next operation,

Pseudo code like the following:
 UINT __cdecl ThreadProc (... ) 
{
.
MSG MSG.
while(! BExitThread & amp; & GetMessage (& amp; MSG, NULL, 0, 0, 0)
{
The switch (MSG) message)
{
Case MSG_XXX:
{
//perform calculations, filling structure data, send a custom message to inform the UI thread,
}
}
}
.
}


LRESULT OnXXXXX (WPARAM, LPARAM)//UI thread custom message handler
{
//parse the data, UI updates
PostThreadMessage (... );//notice threads to execute the next operation
}

Refresh work sometimes longer, so I opened a worker thread is responsible for the refresh, avoid main interface card, or directly in the Ui thread

CodePudding user response:

Guard_lock normally won't lock, temporary variables destructor will automatically unlock

CodePudding user response:

Seem to find the reason, the worker thread in the main interface in the process of the list, the main thread has reached the awaited state after the refresh function setitemtext will be blocked, the child thread is in a wait state, the UI thread locking, worker threads can't refresh the UI controls
  • Related