Repository navigation
OrchestrateLang v0.13.0
State a worker can touch, declared rather than assumed.
Added
-
shared let. A top-levelletbelongs to the instance and only hooks reach it,
because a spawned worker can run while a tick holds it. The existing answer for state
several concurrent things touch is a serverlet, at about 7.5 µs a call.shared letis
the rung between: one mutex instead of a channel round trip.let counter = 0 // unchanged: instance-owned, hooks only, free shared let hits = 0 // any task, any fn, synchronisedThe guarantee is one sentence: a statement that touches shared state is atomic with
respect to all shared state. All shared bindings live behind a single mutex, taken once
per statement, sohits = hits + 1is correct without anyone thinking about it and there
is no lock order to get wrong. Reads clone, because a value cannot be moved out of a
guard; for a number that is a copy.A statement may wait, or touch shared state — not both. Holding the lock across a
wait would block every other reader, so it is a compile error saying to split the
statement. Because the lock is synchronous, a plainfncan touch shared state, which
afncould never do with instance state.A shared binding is never captured by a worker or an event handler: capturing would copy
the value and quietly undo the sharing, so it is reached through the lock wherever it is
used. In library mode it lives on the instance, so two libraries started in one process
do not share it. Data can be shared —int,float,bool,string, arrays, options
and structs; a serverlet client, a process, or a closure is refused by name.A program without
shared letgains no mutex, no field, and no code. The design, and the
five questions it opened and how each was answered, are indocs/design/shared-state.md.