-
Notifications
You must be signed in to change notification settings - Fork 0
add
ffredyk edited this page Jul 23, 2026
·
1 revision
Shared (Atomic) / Arithmetic
Binary — <shared|number> add <number>.
<shared> add <number> // atomic increment
<number> add <number> // regular addition
Dual-purpose addition command:
- On Shared variable: performs an atomic increment. Thread-safe from any scheduler. Returns the new value.
-
On regular number: performs standard addition (same as
+). Returns the sum.
Auto-unwraps shared values when used on regular numbers.
- Shared: uses
Interlocked.Add(or equivalent CAS loop) for atomic increment. The operation is indivisible — no other fiber can see a partial state. - Number: delegates to the standard
+implementation.
shared _counter = 0;
_counter add 1; // atomic — safe from any fiber
_counter add 5; // atomic add 5shared _kills = 0;
// Called from any scheduler:
_kills add 1; // thread-safe kill counter_result = 3 add 4; // 7 (same as 3 + 4)
_x = _x add 1; // increment (not atomic for regular vars)shared _totalDamage = 0;
// Multiple fibers add damage:
_totalDamage add _incomingDamage;
// Later:
_damageSum = get _totalDamage;shared _counter = 0;
_counter add 1; // ATOMIC — correct
_counter = get _counter + 1; // NOT atomic — race condition!Always use add (or compareSwap) for shared variable modification. Never use get + arithmetic + set — it creates a race condition.
- On Shared: Fully atomic. Thread-safe from any scheduler.
- On Number: Standard computation. Thread-safe for value types.
- sub — atomic subtract
- get — atomic read
- set — write (not atomic on shared)
- compareSwap — atomic CAS
- + — standard addition
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo