back forward index

My Experiments with Win32:Mutex

Dated 11th December 1998
I have a Win 95 machine at home and I haven't been able to get Win32: Mutex fully running to my satisfaction.
Perl version is Standard distribution
perl -v
This is perl, version 5.004_02
Copyright 1987-1997, Larry Wall
 

What I have Observed so Far

  1. Win32::Mutex::Create returns zero if successful and nonzero (1) if unsuccessful.(Don't use ||die directly !!) It correctly sets Win32::GetLastError.
  2. Win32::Mutex::Wait returns zero if successful and nonzero (258 ?) if unsuccessful.(So you can't use ||die directly as it expects the opposite) It does not seem to set Win32:GetLastError.
  3. $Mutex->Wait(INFINITE) seems to return immediately !! So use a large wait time,a loop and check for a zero return value.
  4. However when you use a large value of Wait {I was using 50 Seconds i.e Wait(50000) }I found that even if the mutex became available it wasn't being locked by the script 
  5. Win32::Mutex::Open  returns 1 if successful and zero if unsuccessful. It sets Win32::GetLastError
  6. Win32::Mutex::Release  returns 1 if successful and zero if unsuccessful. It sets Win32::GetLastError
  7. If I try to open a mutex which has not yet been created I get the Error "No such File Or Directory" in $!. Win32:GetLastError has a more appropriate message "Cannot create a file when that file already exists." Don't trust $!
Here is the example script for Win32::Mutex
It creates a mutex and accesses it 9 times.
To see the fun run multiple copies of the script simultaneously.Only one will be in it's critical section at any time.
 Mutex.pl
Finally Here is a Link to a new module which is supposed to Do mutexes. I haven't looked at it yet. When I do I'll post a review Check out Fmutex.zip

Back to Perl Homepage 


Copyright © Robin S. Chatterjee. All rights reserved.

Updated on 7th October 1998

back forward index