in reply to Re^16: Threads sharing global variable (disingenous)
in thread Threads sharing global variable
The following resolves the printer output having two zeros. That led to the confusion. It looks like somebody already mentioned it.
$a = int(rand() * 100) + 1;
The OP presented an interesting problem. Seeing the double zeros led me on a wrong path. Please, for future monks testing your solution, can you kindly add + 1 inside set_positive.
sub set_positive { lock $a; while (1) { if ($a == 0) { $a = int(rand() * 100) + 1; $q->enqueue($a); print "At set_positive: $a\n"; } else { cond_wait($a) } cond_broadcast($a); } }
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^18: Threads sharing global variable (disingenous)
by BrowserUk (Patriarch) on Mar 10, 2016 at 16:02 UTC | |
|
Re^18: Threads sharing global variable (disingenous)
by Anonymous Monk on Mar 10, 2016 at 15:57 UTC |