Base class: Object

Lua
C++
Edit

Mutex

A mutex ("mutually exclusive") is used to define a block of code that two threads may not execute at the same time. Use of mutexes should be minimized, as they can slow down multi-threaded code so that it loses its advantages over single-threaded code.

Properties

Name Type Description
Lock Method Locks the mutex
Unlock Method Unlocks the mutex
CreateMutex Function Creates a new mutex

Examples

-- Create a new mutex
local mutex = CreateMutex()

-- Thread 1
mutex:Lock()
-- Code that should not be executed by both threads at the same time
mutex:Unlock()

-- Thread 2
mutex:Lock()
-- Code that should not be executed by both threads at the same time
mutex:Unlock()

Note: The example assumes that multi-threading is already set up in Lua.

Copyright © 2024 Ultra Software.
All rights reserved.