PhantomScript v1.7 Reference - Copyright © 2006 P1 Systems Incorporated. All Rights Reserved.

Prev | Next | Users Guide | PhantomScript Reference | P1 Systems


Process Control

WaitForMutex

Syntax

WaitForMutex MutexName=<name> Timeout=<secs>

Description

Waits for a specified mutex to be signaled.

Parameters

<name>

The name of the mutex for which to wait

<secs>

The number of seconds after which execution will continue refardless of whether the mutex was signaled. The TimedOut intrinsic variable is set to True is this timeout occurs.

Remarks

A mutex is a synchronization mechanism designed to ensure mutually exclusive access to a single resource shared among a set of cooperating processes. A mutex is created when the first process names it in a WaitForMutex statement. Thereafter, other processes naming the mutex access the one created by the first process. If WaitForMutex succeeds (i.e. does not time out), then the calling process "owns" the mutex and no other WaitForMutex requests on that mutex will return sucess until the owning process releases it using the ReleaseMutex statement. A mutex should be closed using CloseMutex when the script has no plans to use it again.

Example

          WaitForMutex MutexName="FileAccess" Timeout=60
If Not TimedOut Then
LoadFile buffer "SharedFile.dat"
... change file contents ...
SaveFile "SharedFile.dat" buffer
ReleaseMutex MutexName="FileAccess"
Else
... perform error actions ...
Endif
... all done ...
CloseMutex MutexName="FileAccess"

The example allows cooperating processes to arrange that one and only one of the process has access to the file SharedFile.dat at a time by synchronizing on the FileAccess mutex.



Prev | Next | Users Guide | PhantomScript Reference | P1 Systems

PhantomScript v1.7 Reference - Copyright © 2006 P1 Systems Incorporated. All Rights Reserved.