PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Principle
  • How to implement a mutex?
  • The steps:
  • Notes
  • The functions for managing the mutexes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
The mutexes are used to limit the simultaneous execution of a code (procedure, code line, ...) to one thread at a given time. A mutex can be shared between several applications.
Note: Other systems can also be used to protect a code section:
  • the semaphores are used to limit the simultaneous execution of a code (procedure, code line, ...) to one or more threads at a given time. A semaphore can be shared between several applications.
  • the critical sections are used to limit the simultaneous execution of a code (procedure, code line, ...) to one thread at a given time in a single application.
Versions 18 and later
Universal Windows 10 App This feature is now available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This feature is now available in Windows Store apps mode.
Universal Windows 10 App This feature is now available in Windows Store apps mode.
Versions 19 and later
iPhone/iPad This feature is now available for the iPhone/iPad applications.
WINDEVLinux This feature is now available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This feature is now available for the WEBDEV sites in Linux.
New in version 19
iPhone/iPad This feature is now available for the iPhone/iPad applications.
WINDEVLinux This feature is now available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This feature is now available for the WEBDEV sites in Linux.
iPhone/iPad This feature is now available for the iPhone/iPad applications.
WINDEVLinux This feature is now available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This feature is now available for the WEBDEV sites in Linux.
Principle
The mutex was created by MutexCreate.
  1. Thread #1 runs MutexStart: no thread is currently found in the mutex.
  2. Thread #1 runs the code section protected by the mutex.
  3. While thread #1 runs the code protected by the semaphore, thread #2 runs MutexStart: the code protected by the mutex being currently run by thread #1, thread #2 must wait for the mutex to be freed.
  4. Thread #1 runs MutexEnd: no other thread runs the mutex code.
  5. Thread #2 can run the code protected by the mutex.
  6. Thread #2 runs MutexEnd: no other thread runs the mutex code.
How to implement a mutex?

The steps:

The different steps for implementing a mutex are as follows:
  1. Creating a mutex with MutexCreate. The mutex is associated with a name.
  2. Calling MutexStart before the code section to protect.
  3. Calling MutexEnd to define the code section to protect. The code lines found after MutexEnd will not be protected anymore.
  4. Destroying the mutex with MutexDestroy.

Notes

  • The code sections protected by a mutex must be as short as possible and they must only affect the "critical" processes.
  • When a thread is pending, the resources of the processor are not used.
  • The mutexes apply to the main thread and to the secondary threads (created by ThreadExecute). You must avoid locking the main thread. Indeed, if the main thread is locked (pending), the application cannot be run anymore.
  • MutexStart and MutexEnd must be used in the same process (in a procedure for example).
  • The mutexes can be shared (or not) between the different applications run on the computer. All you have to do is specify the share mode of mutexes during their creation (MutexCreate).

The functions for managing the mutexes

The following WLanguage functions are used to manage the mutexes:
Versions 16 and later
MutexCreate
New in version 16
MutexCreate
MutexCreate
Explicitly creates a mutex.
Versions 16 and later
MutexDestroy
New in version 16
MutexDestroy
MutexDestroy
Explicitly destroys a mutex.
Versions 16 and later
MutexEnd
New in version 16
MutexEnd
MutexEnd
Signals that the thread frees the mutex.
Versions 16 and later
MutexStart
New in version 16
MutexStart
MutexStart
Locks the current thread while waiting for the mutex to be freed.
Minimum required version
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment