Synchronization Variables¶
Synchronization variables have a logical state associated with the value. The state of the variable is either full or empty. Normal reads of a synchronization variable cannot proceed until the variable’s state is full. Normal writes of a synchronization variable cannot proceed until the variable’s state is empty.
Chapel supports two types of synchronization variables: sync and single. Both types behave similarly, except that a single variable may only be written once. Consequently, when a sync variable is read, its state transitions to empty, whereas when a single variable is read, its state does not change. When either type of synchronization variable is written, its state transitions to full.
If a task attempts to read or write a synchronization variable that is not in the correct state, the task is suspended. When the variable transitions to the correct state, the task is resumed. If there are multiple tasks blocked waiting for the state transition, one is non-deterministically selected to proceed and the others continue to wait if it is a sync variable; all tasks are selected to proceed if it is a single variable.
- proc isSyncType(type t) param¶
Returns true if t is a sync type, false otherwise.
- proc sync.readFE()¶
Block until the sync variable is full.
Read the value of the sync variable and set the variable to empty.
- Returns
The value of the sync variable.
- proc sync.readFF()¶
Block until the sync variable is full.
Read the value of the sync variable and leave the variable full
- Returns
The value of the sync variable.
- proc sync.readXX()¶
Read the value of the
sync
variable. For a fullsync
, returns a copy of the value stored. For an emptysync
, the implementation will return either a new default-initialized value of the value type or the last value stored.Does not change the full/empty state
- Returns
The value of the sync variable.
- proc sync.writeEF(in x: valType)¶
Block until the sync variable is empty.
Write the value of the sync variable and leave the variable full
- Arguments
val – New value of the sync variable.
- proc sync.writeFF(in x: valType)¶
Block until the sync variable is full.
Write the value of the sync variable and leave the variable full
- Arguments
val – New value of the sync variable.
- proc sync.writeXF(in x: valType)¶
Write the value of the sync variable and leave the variable full
- Arguments
val – New value of the sync variable.
- proc sync.reset()¶
Resets the value of this sync variable to the default value of its type. This method is non-blocking and the state of the sync variable is set to empty when this method completes.
- proc sync.isFull¶
Determine if the sync variable is full without blocking. Does not alter the state of the sync variable
- Returns
true if the state of the sync variable is full.
- proc isSingleType(type t) param¶
Returns true if t is a single type, false otherwise.
- proc single.readFF()¶
Block until the single variable is full.
Read the value of the single variable and leave the variable full
- Returns
The value of the single variable.
- proc single.readXX()¶
Read the value of the
single
variable. For a fullsingle
, returns a copy of the value stored. For an emptysingle
, the implementation will return either a new default-initialized value of the value type or the last value stored.Does not change the full/empty state
- Returns
The value of the
single
variable.
- proc single.writeEF(in x: valType)¶
Block until the single variable is empty.
Write the value of the single variable and leave the variable full
- Arguments
val – New value of the single variable.
- proc single.isFull¶
Determine if the single variable is full without blocking. Does not alter the state of the single variable
- Returns
true if the state of the single variable is full.