Revision [16962]

This is an old revision of KeyPgMutexCreate made by FxMwikki on 2013-09-27 14:06:07.



Creates a mutex used for synchronizing the execution of threads

result = Mutexcreate

Return Value:
The KeyPgAny any KeyPgPtr ptr handle of the mutex created, or the null pointer (0) on failure.

Mutexes, short for "Mutually Exclusive", are a way of synchronizing shared data within threads. If there is a global variable used by multiple threads (or a local variable used by a single thread, called multiple times), it should be "locked" during its use with a mutex. This halts all threads using KeyPgMutexLock Mutexlock with that mutex (including the main thread executing main program), until it is unlocked with KeyPgMutexUnlock Mutexunlock.
Mutexcreate creates a mutex, returning a handle which is to be referred to when locking, unlocking, or destroying the mutex. Mutexes created with Mutexcreate should be destroyed when no longer needed or before the end of the program with KeyPgMutexDestroy Mutexdestroy.

A mutex is a lock that guarantees three things:
1. Atomicity - Locking a mutex is an atomic operation, meaning that the operating system (or threads library) assures you that if you locked a mutex, no other thread succeeded in locking this mutex at the same time.
2. Singularity - If a thread managed to lock a mutex, it is assured that no other thread will be able to lock the thread until the original thread releases the lock.
3. Non-Busy Wait - If a thread attempts to lock a thread that was locked by a second thread, the first thread will be suspended (and will not consume any CPU resources) until the lock is freed by the second thread. At this time, the first thread will wake up and continue execution, having the mutex locked by it.

See the KeyPgThreadCreate Threadcreate examples.

Dialect Differences:
Platform Differences:
Differences from QB:
See also:
Back to Threading Support Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode