Win32::Semaphore - Use Win32 semaphore objects from Perl


Win32::Semaphore - Use Win32 semaphore objects from Perl

SYNOPSIS require Win32::Semaphore;

        $sem = Win32::Semaphore->new($initial,$maximum,$name);


This module allows access to Win32 semaphore objects. The wait method and wait_all & wait_any functions are inherited from the Win32::IPC module.


$semaphore = Win32::Semaphore->new($initial, $maximum, [$name])
Constructor for a new semaphore object. $initial is the initial count, and $maximum is the maximum count for the semaphore. If $name is omitted, creates an unnamed semaphore object.

If $name signifies an existing semaphore object, then $initial and $maximum are ignored and the object is opened.

$semaphore = Win32::Semaphore->open($name)
Constructor for opening an existing semaphore object.

$semaphore->release([$increment, [$previous]])
Increment the count of $semaphore by $increment (default 1). If $increment plus the semaphore's current count is more than its maximum count, the count is not changed. Returns true if the increment is successful.

The semaphore's count (before incrementing) is stored in the second argument (if any).

It is not necessary to wait on a semaphore before calling release, but you'd better know what you're doing.

Wait for $semaphore's count to be nonzero, then decrement it by 1. See Win32::IPC.

Deprecated Functions and Methods

Win32::Semaphore still supports the ActiveWare syntax, but its use is deprecated.

Use $SemObject = Win32::Semaphore->new($Initial,$Max,$Name) instead.

Win32::Semaphore::Open($SemObject, $Name)
Use $SemObject = Win32::Semaphore->open($Name) instead.

Use $SemObj->release($Count,$LastVal) instead.


Christopher J. Madsen <>

Loosely based on the original module by ActiveWare Internet Corp.,

 Win32::Semaphore - Use Win32 semaphore objects from Perl