in reply to Semaphores failing to prevent race condition

I written a lot of threaded perl code over the last 8 or 9 years, and I've never had occasion to use Thread::Semaphore. To me it seems to be a very complicated (and apparently broken) way to do something very simple.

I would ditch that module in favour of a very simple mechanism.

my $outputSem :shared; ... if ($success) { lock $outputSem; erase($input_window); addstr($input_window, $buffer); refresh($input_window); $ptr = length($buffer); curs_to_ptr($input_window, $ptr); } ... sub icb_print { my ($window, $color, $fmt, @args) = @_; my $buf = sprintf ($fmt, @args); lock $outputSem; ... }

No guarantees given I cannot see never mind run most of your code, but that simple change will probably fix your problems.


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.

Replies are listed 'Best First'.
Re^2: Semaphores failing to prevent race condition
by Llew_Llaw_Gyffes (Scribe) on Mar 13, 2011 at 19:22 UTC
    I think I'm going to try this first, given that at this point I'm rather suspicious of Thread::Semaphore.

      Not conclusive yet, as the client's only been running about three days, but it looks as though this simple fix solved the problem.

      The answer seems to be that Thread::Semaphore is, ironically, not thread-safe.

        The answer seems to be that Thread::Semaphore is, ironically, not thread-safe.

        Thanks for the update, and please do continue to keep us (me) informed.

        Unfortunately there are a bunch of modules in the Thread::* namespace that were never tested in multi-core or multi-cpu setups. Getting a handle on which ones are broken is useful information.

        Better yet, once you're convinced that Thread::Semaphore is the source of your problems, a bug report against it might see it corrected, or at least a documentation change to reflect the problem.


        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.