While others have commented on alternative methods to the overarching problem, I wanted to address the specific question of a 'boolean' semaphore. One 'brain-dead' simple approach would be to sub-class Thread::Semaphore such that the ->up() operation sets the semaphore to 1 rather than incrementing it.
package Thread::Semaphore::Boolean; use threads::shared; use parent 'Thread::Semaphore'; # Create a new 'boolean' semaphore sub new { my $class = shift; return $class->SUPER::new(1); } # Set semaphore's count to 1 sub up { my $sema = shift; lock($$sema); $$sema = 1; cond_broadcast($$sema); } 1;
Again, this is 'brain-dead' in that elementary uses of ->down() and ->up() will work, whereas other 'fancy' operations may break (e.g., $sema->down(2) would 'hang' because the 'boolean' semaphore would never be greater than 1).

In reply to Re: Boolean Thread::Semaphore ? by Anonymous Monk
in thread Boolean Thread::Semaphore ? 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!
  • 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:
    & &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.