Lyricdev
GitHub

LYR-RT0019

a lock poisoned by a panic

panic ยท spec 10-concurrency

A task acquires a Mutex, RwLock or Once whose holder panicked while it held it. The scheduler released the lock and poisoned it; the panic names the first panic's code and message.

Program

import std.task { spawn, yieldNow };
import std.sync { Mutex };

fn main(): void throws Error {
    let m = Mutex<int>.new(0);
    let t = spawn(() => {
        try m.lock { &n =>
            n = 1;
            panic("inside");
        };
    });
    while (!t.isDone()) {
        try yieldNow();
    }
    let v = try m.lock { &n => n };
    assert(v == 1);
}