Yes, it would need more than that one line changing, but something like this ought to be close:

package threads::RWLock; use threads; use threads::shared; BEGIN { $VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d +."."%02d" x $#r, @r }; # must be all one line, for MakeMaker } =head1 FUNCTIONS AND METHODS =over 8 =item new C<new> creates a new rwlock. The new rwlock is unlocked. =cut sub new { my $class = shift; my %self : shared; my $self = bless \%self, $class; my %anon : shared; $self->{locks} = 0; $self->{locker} = \%anon; $self->{writer} = 0; return $self; } =item down_read The C<down_read> method obtains a read lock. If the lock is currantly held by a writer or writer are waiting for the lock, C<down_read> bloc +ks until the lock is available. =cut sub down_read { my $self = shift; lock $self; if ($self->{locker}->{threads->self->tid}++) { return; } cond_wait $self until $self->{locks} >= 0 && $self->{writer} == 0; $self->{locker}->{threads->self->tid} = 1; $self->{locks}++; } =item up_read Releases a read lock previously obtained via C<down_read>. =cut sub up_read { my $self = shift; lock $self; if (--$self->{locker}->{threads->self->tid} == 0) { $self->{locks}--; if ($self->{locks} == 0) { cond_broadcast $self; } } } =item down_write Obtains a write lock from the rwlock. Write locks are exclusive, so no other reader or writer are allowed until the lock is released. C<down_write> blocks until the lock is available. =cut sub down_write { my $self = shift; lock $self; $self->{writer}++; cond_wait $self until $self->{locks} == 0; $self->{locks}--; } =item up_write Release a write lock previously obtained via C<down_write>. =cut sub up_write { my $self = shift; lock $self; $self->{writer}--; $self->{locks} = 0; cond_broadcast $self; } =back =head1 SEE ALSO the Thread::Semaphore manpage =head1 AUTHOR Andreas Ferber <aferber@cpan.org> Tentatively modified for iThreads by BrowserUk@perlmonks =cut 1;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Thread::RWLock for 5.8 threads ? by BrowserUk
in thread Thread::RWLock for 5.8 threads ? by renodino

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.