develooper Front page | perl.perl5.porters | Postings from June 2003

Re: P and V

Thread Next
From:
Philip Newton
Date:
June 25, 2003 08:50
Subject:
Re: P and V
Message ID:
3EF9E0DE.4786.16A6869@localhost
On 5 May 2003 at 20:54, Jarkko Hietaniemi wrote:

> http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2003-04/msg00112.html
> 
> Based on Abigail's explanation could you prepare your patch?
> (Including the P and V explanation would be a nice touch.)

Here you go; apologies for the delay. Tell me what you think.

--- lib/Thread/Semaphore.pm.orig	2002-07-13 01:51:27.000000000 +0100
+++ lib/Thread/Semaphore.pm	2003-06-25 16:44:14.000000000 +0100
@@ -12,14 +12,14 @@

     use Thread::Semaphore;
     my $s = new Thread::Semaphore;
-    $s->up;	# Also known as the semaphore V -operation.
+    $s->down;	# Also known as the semaphore P operation.
     # The guarded section is here
-    $s->down;	# Also known as the semaphore P -operation.
+    $s->up;	# Also known as the semaphore V operation.

     # The default semaphore value is 1.
     my $s = new Thread::Semaphore($initial_value);
+    $s->down($down_value);
     $s->up($up_value);
-    $s->down($up_value);

 =head1 DESCRIPTION

@@ -29,7 +29,7 @@

 Semaphores don't limit their values to zero or one, so they can be 
used to
 control access to some resource that there may be more than one of. 
(For
-example, filehandles). Increment and decrement amounts aren't fixed at 
one
+example, filehandles.) Increment and decrement amounts aren't fixed at 
one
 either, so threads can reserve or return multiple resources at once.

 =head1 FUNCTIONS AND METHODS
@@ -53,6 +53,10 @@
 count is equal to or larger than the amount you're C<down>ing the
 semaphore's count by.

+This is the semaphore "P operation" (the name derives from the Dutch
+word "pak", which means "capture" -- the semaphore operations were
+named by the late Dijkstra, who was Dutch).
+
 =item up

 =item up NUMBER
@@ -62,6 +66,9 @@
 trying to C<down> the semaphore if the C<up> raises the semaphore 
count
 above the amount that the C<down>s are trying to decrement it by.

+This is the semaphore "V operation" (the name derives from the Dutch
+word "vrij", which means "release").
+
 =back

 =cut
End of patch.

Cheers,
Philip
-- 
Philip Newton <pnewton@gmx.de>
I appreciate copies of replies to my messages to Perl5 lists.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About