Mutex/Lock File Action



The Mutex/Lock File Action allows you to establish access to an exclusive resource. The resource can be either a lock file or a global Windows mutex object. The action can be used to control exclusive access within a FinalBuilder project, between multiple concurrent instances of FinalBuilder, or between FinalBuilder and a different application.


The exclusive access lasts until all child actions have finished running.






In the above example, exclusive access to the lock file "\\server\shared\access.lck" will be established, then all of the child actions will run. Once the last action, "Write To Text File", has completed, the file will be released.





Lock File


If this option is set, the specified file path will be locked exclusively. The action will block until it obtains exclusive access to the file, or a timeout is reached. No access (read, write or delete) is allowed to the file until the lock action releases it.


Create file if it doesn't exist - If this option is not enabled, and the file to lock is not found at runtime, then the action will fail.


Delete the file when releasing the lock - Enable this option to delete the file when the exclusive lock is released.


Note that because the file is locked, child actions of the Mutex/Lock File Action will not be able to access the file. It is not recommended that you lock files which contain the data you intend to use. Instead, create a dedicated lock file.


Shared server files can be specified by using UNC paths, as shown above. Note that FinalBuilder will need full access to the network share.



Lock Global Mutex Object


Mutexes are a class of Windows operating system object. FinalBuilder allows you to acquire and release mutexes which belong to the system's Global namespace, which is shared between all other processes on the system.


Mutex name - Specify the name of the global mutex to acquire when the action runs (and release once all children are completed.) In Windows, the full name of the mutex will be "Global\<MutexName>".


Create mutex if it doesn't exist - Check this box in order to create the mutex if it is not found at runtime. You should only disable this option if you know for certain that the mutex has been created and retained by another process. This is because mutex objects are deleted as soon as no process retains a handle to them. The action does not keep a handle to the mutex object it uses, except for when the mutex is acquired.





You can set a timeout for the action under the "Runtime" -> "Timing Settings" tab. The action will fail if the timeout is reached and the mutex or file is still unavailable.