slloyd has asked for the wisdom of the Perl Monks concerning the following question:
Mutex Code
#!perl -w use strict; $|=1; use Win32::Mutex; my $mutexname="PIGMania"; if(Win32::Mutex->open($mutexname)){ print "must be already running"; exit; } my $mutex=Win32::Mutex->new(1,$mutexname); $mutex->wait(3); print "Mutex: $mutex\n"; my $x=30; while($x){ print "."; select(undef,undef,undef,1.5); $x--; }
Semaphore Code
#!perl -w use strict; $|=1; use Win32::Semaphore; my $semaphore_name="PIGMania"; if(Win32::Semaphore->open($semaphore_name)){ print "$semaphore_name is already running\n"; exit; } my $semaphore=Win32::Semaphore->new(1,1,$semaphore_name); print "Semaphore: $semaphore\n"; my $x=30; while($x){ print "."; select(undef,undef,undef,1.5); $x--; }
-------------------------------
Need a good Perl friendly Host Provider?
http://www.dreamhost.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Win32::Mutex to guarantee only one process will run at a time.
by Anonymous Monk on Feb 08, 2007 at 23:43 UTC |