Sounds like a deadlock - your thread that’s calling stopThread will already have the message manager locked, but maybe the other thread is at the same time waiting to lock the messagemanager so it can send its listener callback?
[quote=“X-Ryl669”]You can use this deadlock detector to locate exactly where your deadlock occurs…
(Simply build in release with the generate .MAP file option)[/quote]
how on earth does this thing work? does not seem to do anything!
load map then process? ??
anyway…
how should I go about stopping a thread that uses MMLs? At the moment I’ve got a boolean guard condition around the attempt to take MML and I’ve added a Thread::sleep( 100 ) before the stopThread(-1) to allow any immediatly pending MML requirements to complete.
pseudocode for stopping…
set acceptevents = false
sleep 100
stopthread ( threadWotSendsTheEvents )
for event callback
procedure onEvent
start
if acceptevents
start
get MML
doGUIStuff
end
end
good? bad? terrible? dodgy archetecture to begin with?
For the deadlock detector,
[list]
[]Click on the open icon (and select your EXE)[/]
[]The process load and inject the dll inside (you should have a message box)[/]
[]Do like you would in real life until the deadlock happens[/]
[]When you’ve passed the usually deadlocking state, click on “File/Load map file”[/]
[] Select the map file that is link with your exe[/]
[] Click analysis menu/ Full analysis[/]
[] The list update as long as the analysis goes. The deadlock are shown in orange (warning-understand might deadlock in release mode) or dark-red(real deadlock).
If the map file is correct, you’ll have the last function name on the last column.[/][/list]
Adding sleep is never a good idea (it masks the problem but doesn’t solves it).
[quote=“X-Ryl669”]For the deadlock detector,
[list]
[]Click on the open icon (and select your EXE)[/]
[*]The process load and inject the dll inside (you should have a message box)
[/quote]
crashed here in >ThreadSpy.dll!1000421b()
[quote][/]
[]Do like you would in real life until the deadlock happens[/]
[]When you’ve passed the usually deadlocking state, click on “File/Load map file”[/]
[] Select the map file that is link with your exe[/]
[] Click analysis menu/ Full analysis[/]
[] The list update as long as the analysis goes. The deadlock are shown in orange (warning-understand might deadlock in release mode) or dark-red(real deadlock).
If the map file is correct, you’ll have the last function name on the last column.[/*][/list]
Adding sleep is never a good idea (it masks the problem but doesn’t solves it).[/quote]
what are alternatives? more locks? the sleep is just to allow anything currently inside the event callback to finish.
I’ve sent to your email address the last version of the deadlock detector.
Try to use the compiled version, and if doesn’t work compile it yourself in release mode.
Concerning your “solution”, the problem will happen if the other threads take longer to finish than your “wait” time. This usually happens when the computer is very, very busy, CPU is full etc…
So you’ll probably say let’s wait longer. Doing so will simply decrease the reactiveness of your software while still suffering from the previous bug.
The only solution I’ve found to prevent deadlock so far is to draw the thread object locking order (you’ll have to take a very long piece of paper).
Something like thread A locks object 1 then object 2 then object 3, release object 2 then object 3 then 1 then locks object 2 release it, etc…
At the same time thread B locks object 1 then object 3 then object 2, release 2 then 3
If two threads cross their object locking order (like in the previous example it is going to deadlock on object 3 and 2) they will deadlock.
To prevent this, always lock the objects in the same order in all threads.
BTW, the deadlock detector simply does this checking for you.
[quote=“X-Ryl669”]I’ve sent to your email address the last version of the deadlock detector.
Try to use the compiled version, and if doesn’t work compile it yourself in release mode.
Concerning your “solution”, the problem will happen if the other threads take longer to finish than your “wait” time. This usually happens when the computer is very, very busy, CPU is full etc…
So you’ll probably say let’s wait longer. Doing so will simply decrease the reactiveness of your software while still suffering from the previous bug.
The only solution I’ve found to prevent deadlock so far is to draw the thread object locking order (you’ll have to take a very long piece of paper).
Something like thread A locks object 1 then object 2 then object 3, release object 2 then object 3 then 1 then locks object 2 release it, etc…
At the same time thread B locks object 1 then object 3 then object 2, release 2 then 3
If two threads cross their object locking order (like in the previous example it is going to deadlock on object 3 and 2) they will deadlock.
To prevent this, always lock the objects in the same order in all threads.
BTW, the deadlock detector simply does this checking for you.[/quote]