|The stupid question is the question not asked|
Re: How to debug perl code that uses threadsby BrowserUk (Pope)
|on Nov 23, 2011 at 10:09 UTC||Need Help??|
The real answer to debugging threads is to design the code for ease of development/debugging from the outset. Which as far as threads is concerned, means designing each individual thread as a linear flow or data-driven loop with as few inter-thread communications and no synchronisation points. And ensuring that those few inter-thread communications are done via tried and tested mechanisms.
This allows each thread to be tested individually by mocking up its communications flow in a light-weight test environment. Once all the parts have been proven to work alone, testing them together becomes a process of monitoring or tracing the combined communication flows.
But none of that helps you given your situation.
My approach to your problem would be ignore the debugger at the start and add a few trace lines into the actual code at critical points. The trace would be written to a new queue added for the purpose and would consist of (just):
I'd start another thread who's only purpose is to simply write everything on the queue to a file.
By writing this minimal information to a queue, you have minimal impact upon the code under test whilst obtaining a clear overall picture of the flows through the program without producing too huge a trace file to have to plough your way through.
I've also tended to add a ^C interrupt handler in main that simply injects a flag into the trace queue. This is useful when the program manifests behaviour the programmer can see and may want to investigate. You just hit ^C when you see the event occur, and it adds a flag to the trace for off-line investigation later.
If the program uses one or more pools of identical worker threads, temporarily reduce the number of each type to one. It greatly simplifies the trace.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.