// Default thread type
let handle = spawn worker_fn(data);
// Explicit thread type
let handle = spawn worker_fn(data) with GreenThread;
// Fire-and-forget
let _ = spawn background_task();
// #wont_remain -- promise the thread dies before the scope ends
#wont_remain let _ = spawn quickTask(sharedData);
If a thread accesses shared data, the compiler requires one of:
await handle before the shared data goes out of scope, or#wont_remain attribute on the spawn.Missing both is a compile error. Violating the #wont_remain promise is not caught by the compiler — the shared data may become a dangling reference. An alternative to both is using global: share T or Rc.
| Keyword / Method | Semantics |
|---|---|
await handle |
Waits for the thread to finish. |
await globalVar |
Blocks until the global variable has been initialized. |
handle.send(msg) |
Sends a message to the running thread. |
#wont_remain |
Attribute on spawn. Promises the thread dies before the enclosing scope ends. |
let handle = spawn worker(sharedData);
await handle;
global cfg: Config;
await cfg;
@println(cfg.host);
Zith Language Specification — Draft v0.9