Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) 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):

threadId timestamp linenumber

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.

In reply to Re: How to debug perl code that uses threads by BrowserUk
in thread How to debug perl code that uses threads by chrestomanci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2014-09-20 03:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (152 votes), past polls