in reply to Re^4: Threads sharing global variable
in thread Threads sharing global variable

Hi Tanktalus, I'm running on windows

update:

FWIW, if I only move the lock in set_positive inside the while loop, still just one line of output.

If I only move the lock in set_zero inside the while loop, a couple thousand lines of output, and then it locks hangs

If I move both the lock statements inside the while loop, like BrowserUk wrote, it just keeps running and doesn't hang

Replies are listed 'Best First'.
Re^6: Threads sharing global variable
by ikegami (Patriarch) on Mar 09, 2016 at 13:40 UTC
    For me, it works fine in Windows too.
    C:\Users\ikegami>perl a.pl At printer 2 0 At printer 93 0 At printer 94 0 At printer 60 0 At printer 26 0 At printer 83 0 At printer 65 0 At printer 45 0 At printer 8 0 At printer 20 0 At printer 7 0 At printer 47 0 At printer 53 0 At printer 22 0 At printer 26 0 At printer 22 0 At printer 24 0 At printer 51 0 At printer 13 0 At printer 100 0 ...
    This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +64-multi-thread

      This is your most disingenuous post to date. (The latest in a very long line.)

      Below is a simple experiment using your exact posted code from Re^2: Threads sharing global variable; that anyone running windows and a few versions of perl installed, can conduct for themselves in around five minutes, and see your dishonesty for themselves.

      This is your code running under This is perl, v5.10.1 built for MSWin32-x64-multi-thread:

      Summary: It produces 287(*) lines of output before hanging. (Varies from run to run; but that's typical.)

      This is your code running under This is perl 5, version 18, subversion 4 (v5.18.4) built for MSWin32-x64-multi-thread:

      Summary: It produces 817* lines of output. (Usually runs a little longer than under 5.10, but of 20 runs this was the most output before hanging.)

      This is your code running under This is perl 5, version 22, subversion 0 (v5.22.0) built for MSWin32-x64-multi-thread:

        The signal can't be missed as long as cond_signal($c) and the cond_wait($c) while !desired_condition(); are only called when you have the lock. That's why it works for your code. That's why it works for my code. There's a bug in your OS (or emulation) otherwise.

        (Stopped test after it produced 6,951,816 lines and 110,673,920 bytes of output)