Okay, I've run it multiple times. It hangs for me too, but randomly - about 1 out of 25 runs - more often if the machine is under heavy load. I moved the warn statements after the lock in both subs and moved the "warn m-processing" above the signal to reduce the time the variable was unlocked. That
seemed to help, but how do we quantify it?
The $done race was not the only one. Looking at the TRACE output, the warn statements don't get executed uniformly. I guess hat's to be expected, since the threads run asynchronously.
However, when it hangs, I see one of two things: a missed signal or a signal being raised when the other thread isn't waiting.
m-locking
m-waiting
t-Locking
t-Waiting
t-Setting
t-Signalling # look ma, nobody received my signal!
t-Locking
t-Waiting # and now we're both blocked, waiting for the other to c
+all
or (I reconstructed this second scenario from memory)
m-processing
t-Locking
t-Waiting
t-Signalling # if a tree signals in a forest, and noone's listening
t-Locking
t-Waiting
m-locking
m-waiting # and again, we both wait...
Now threads::shared says the following about the second condition:
If there are no threads blocked in a "cond_wait" on the variable,
the signal is discarded. By always locking before signaling, you can
(with care), avoid signaling before another thread has entered
cond_wait().
Uh... what does it mean "with care"?
Two more random notes -
- random lines (from the file to copy) get skipped when TRACE=1, again from missed signals.
- FWIW, 5.8.4 on Debian runs this correctly consistently.
My conclusion is that there's too much happening between lock, wait and signal.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.