Semaphores
Semaphores are mainly used for communication between processes or with external systems.
The system has 256 built-in semaphores, indexed from 0 to 255. Each semaphore can store a 32-bit integer value, ranging from -2147483648 to 2147483647.
All semaphores are reset to 0 after system restart.
Set Semaphore auto_sync
- Function:
set_signalfrom the lua module - Parameters:
- index: [int] Semaphore index
- value: [int] Semaphore value to set
- Returns: [bool] Whether set successfully
Example
set_signal(1, 100)
Increment Semaphore auto_sync
- Function:
add_signalfrom the lua module - Parameters:
- index: [int] Semaphore index
- value: [int] Value to increment
- Returns: [int] Semaphore value after increment. May overflow
Example
add_signal(1, 2)
print(get_signal(1))
Set Multiple Semaphores auto_sync
- Function:
set_signalsfrom the lua module - Parameters:
- index: [int] Semaphore starting index
- values: [list[int]] Semaphore values to set
- Returns: [bool] Whether set successfully
Example
set_signals(1, {1, 2, 3})
Get Semaphore
- Function:
get_signalfrom the lua module - Parameters:
- index: [int] Semaphore index
- Returns: [int] Corresponding semaphore value
Example
print(get_signal(1))
Get Multiple Semaphores
- Function:
get_signalsfrom the lua module - Parameters:
- index: [int] Semaphore starting index
- len: [int] Number of semaphores to get
- Returns: [list[int]] Semaphore value array
Example
values = get_signals(1, 3)
print(values)
Wait Semaphore auto_sync
Blocks and waits until semaphore meets specified condition.
- Function:
wait_signalfrom the lua module - Parameters:
- index: [int] Semaphore index
- value: [int] Value to compare
- relation: [str] Relational Operator
- Returns: [bool] Whether condition is met
Example
wait_signal(1, 100, ">=")
Example
set_signal(1, 2147483647)
print(get_signal(1))
add_signal(1, 2)
print(get_signal(1))
Compatibility Note
signal_set, signal_get, signal_wait, signal_add are aliases for set_signal, get_signal, wait_signal, add_signal respectively.
