- lock ref m as x { … } cancelled { … }: mutex.lock on a ref<mutex<T>>
(a mutex is borrowed for the lock, a ref binding used as is); ok edge:
mutex.borrow bound as x; at every normal exit borrow.end x then
mutex.unlock; the guard is never a source value
- mutex.make/mutex.take; mutex<T> type; ref mr = m lends a mutex
- shield { … }: task.shield.begin/end at every exit (nesting by construction)
- task.check_cancel and task.join_cancel as outcome matches
- select: one borrow per endpoint, send values evaluated first and
deduplicated, every edge binds its own value then the unsent values;
bind count E7005, missing outcome E7004
- linear values never get frame storage (borrowed in place)
- liveness: select handled in the read and after walks
- Quick Reference: select edges bind `job` back (ok(x, job), closed(job));
every Quick Reference example now passes (no PENDING)
- tests: 6 run tests with AIR equivalence (mutex counter, select draw,
select same value, shield, join_cancel forwarding, cancelled recv), 10
rejects (E4304 x3, E3001, E2101, E7005 x2, E7004, E3101 x2, E4101)
- spec 15 §7/§9, quick reference, bundle notes, plan
48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
// A shielded receive is not cancelled; after the shield the task observes the
|
|
// pending cancellation at task.check_cancel.
|
|
// expect: run
|
|
// grant: heap=mem.alloc:64
|
|
// schedules: 20
|
|
// result: 105
|
|
// equivalent: phase3/run/cancel_shield.air
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md
|
|
module demo.cancelshield
|
|
|
|
fn waiter(rx: receiver<u64>) -> u64
|
|
effects [task.wait]
|
|
{
|
|
var v: u64 = 0;
|
|
shield {
|
|
v = channel.recv(rx) or trap;
|
|
}
|
|
channel.close_receiver(move rx) or trap;
|
|
match task.check_cancel() {
|
|
ok => v,
|
|
cancelled => v + 100,
|
|
}
|
|
}
|
|
|
|
fn main(heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc, task.spawn, task.wait]
|
|
{
|
|
match channel.make<u64>(1, heap) {
|
|
ok(tx, rx) => {
|
|
var r: u64 = 0;
|
|
scope sc {
|
|
let t = task.spawn(sc, waiter, move rx);
|
|
task.cancel(t);
|
|
match channel.send(tx, 5u64) {
|
|
ok => {}
|
|
closed(w) => {}
|
|
cancelled(w) => {}
|
|
}
|
|
r = task.join(move t);
|
|
}
|
|
channel.close_sender(move tx);
|
|
r
|
|
}
|
|
err(e) => { trap; }
|
|
}
|
|
}
|