State Management
Variables defined in top-level Init action are automatically global:
action Init:
# These are global state variables
counter = 0
items = []
config = {}
atomic action Increment:
# Access global state directly
counter = counter + 1
No global keyword needed - state variables are automatically accessible everywhere.
Variables defined at the top level (outside actions) are read-only constants:
# Constants (read-only)
MAX_VALUE = 100
TIMEOUT = 30
action Init:
# State variables (read-write)
counter = 0
Variables in functions/actions (not in Init) are local:
atomic func process():
temp = 100 # Local variable (not in state)
return temp * 2
Only self.* variables in roles are part of state:
role Example:
action Init:
self.state_var = 0 # Part of state
local_var = 100 # NOT in state
State variables and top-level constants
Demonstrates: automatic global state, top-level constants
Run in playground
|
|
Expected result (from fizz):
StateSpaceOptions: options:{max_actions:100 max_concurrent_actions:2}
Nodes: 6, queued: 0
Valid Nodes: 6 Unique states: 6
IsLive: true
PASSED: Model checker completed successfully