Page 1 of 1

Detection of blocking thread.

Posted: Wed Oct 05, 2011 4:37 pm
by User_Russian
Hello.
I'm creating a multithreaded program in which a lot of Mutex.
During the program, there is interlocking of multiple threads due to LockMutex.
For some reason the debugger does not fix this situation and I can not figure out which line of the program is blocked (blocking of a Mutex is expected).
Why not add a debugger feature that would be informed about such situations and show a line number in which the interlocking threads function LockMutex().

This can be done as follows.
The debugger should create a thread in the program being debugged.
If you select LockMutex(), stream, creating a debugger will be given a signal LockMutex and line in which it happened.
If you select UnlockMutex(), the debugger will be given information that the Mutex is unlocked.
If within a certain time after performing LockMutex() function will fail UnlockMutex(), then it can be considered interlocking threads and to inform the programmer about this line of code in which it happened.

Re: Detection of blocking thread.

Posted: Wed Oct 05, 2011 4:57 pm
by Ramihyn_
If the debugger where fully thread aware and compatible, you could simply halt the program and would see for each thread where the current execution is. So you would instantly see which thread is halted due to the attempt of accessing a locked mutex.

My first approach to solving this in purebasic, was to replace the mutex commands with macro's which add logging information into a file. Thats simple to do and should point out the problem quickly. In a final compilation for the users, you use a different macro without the logging.

For a more universal solution to different debugging problems with purebasic and threads, you might want to check out my CGKit in the announcement forum. Tell me if you really want to use it, the released version is outdated and i will upload a better version if you want to use it. It has a function where you can write the last X executed source lines of all purebasic threads into a textfile, so you spot those locking problems instantly plus you can backread how your threads got into that situation.

Re: Detection of blocking thread.

Posted: Wed Oct 05, 2011 5:17 pm
by User_Russian
Ramihyn_ wrote:My first approach to solving this in purebasic, was to replace the mutex commands with macro's which add logging information into a file.
Yes, it works I guess.
But it's much more convenient it would be if the data would be functional by default built-in debugger.

Re: Detection of blocking thread.

Posted: Wed Oct 05, 2011 8:15 pm
by PMV
It would be enough to get the current code line of any thread thats
running if you click on the X to stop the debugged program. But i
doesn't know it is that easy to implement. :wink:

MFG PMV