Semaphores
Semaphores are mainly used for inter-process communication or communication 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.
After the system restarts, all semaphores will be reset to 0.
auto_sync
Set Semaphoreset_signal(index, value)
- Parameters
index
: Semaphore index.value
: Value to be set for the semaphore.
auto_sync
Increase Semaphore Valueadd_signal(index, value)
- Parameters
index
: Semaphore index.value
: Value to be added to the semaphore.
- Returns
- The value of the semaphore after the increase. Overflow may occur.
auto_sync
Set Multiple Semaphoresset_signals(index, values)
- Parameters
index
: Starting index of semaphores.values
: Values to be set for the semaphores.
Example Program
set_signals(1, {1,2,3})
Get Semaphore
get_signal(index)
Parameters
index
: Semaphore index.
Returns
- The value of the corresponding semaphore.
Get Multiple Semaphores
values = get_signals(index, len)
- Parameters
index
: Starting index of semaphores.len
: Number of semaphores to get.
Example Program
values = set_signals(1, 3)
print(values)
auto_sync
Wait for Semaphorewait_signal(index, value, relation)
- Parameters
index
: Semaphore index.value
: Value to be compared.relation
: Relational judgment operator.
Example
set_signal(1, 2147483647)
print(get_signal(1))
add_signal(1, 2)
print(get_signal(1))