Real threads
Concurrency in Venutian is real OS level threading, not a simulated event loop. spawn starts a real thread running the call right now and returns a Task immediately; await blocks until it finishes. Shared state crosses threads through share and protect: real mutual exclusion, not a cooperative promise.
:: 'spawn call_expr' starts a real OS thread running the call right now
:: and returns a Task immediately, without waiting. 'await task' blocks
:: until it finishes, returning its result, or re-raising its fault.
make add(a, b)
give a + b
t = spawn add(2, 3)
print kind(t)
print await t
:: several tasks make genuine concurrent progress
make slow_double(n)
sleep(0.05)
give n * 2
t1 = spawn slow_double(1)
t2 = spawn slow_double(2)
t3 = spawn slow_double(3)
print await t1
print await t2
print await t3
:: a fault inside a spawned task surfaces at 'await', not silently
make risky()
give 1 / 0
failing_task = spawn risky()
attempt
await failing_task
rescue e
print "rescued:", e
:: 'share'/'protect': real mutual exclusion across real threads
share counter = 0
make increment_many(count)
i = 0
repeat while i < count
protect counter
counter = counter + 1
i = i + 1
tasks = []
repeat 8 times
tasks = appended(tasks, spawn increment_many(500))
repeat for t in tasks
await t
:: exactly 4000 (8 * 500) every time. 'protect' prevents lost updates
print counter
Task
5
2
4
6
rescued: Division by zero.
4000