import "std/thread.zc" test "Thread Spawn and Join" { "Testing thread spawn and join"; let spawn_result = Thread::spawn(fn(){ "Running on a separate thread"; }); assert(spawn_result.is_ok(), "Thread spawn has failed"); let thr = spawn_result.unwrap(); let join_result = thr.join(); assert(join_result.is_ok(), "Thread join has failed"); } test "Thread Spawn and Detach" { "Testing thread spawn and detach"; let spawn_result = Thread::spawn(fn(){ "Detached thread, this line might print later."; }); assert(spawn_result.is_ok(), "Thread spawn has failed"); let thr = spawn_result.unwrap(); let detach_result = thr.detach(); assert(detach_result.is_ok(), "Thread detach has failed"); } test "Thread Spawn and Cancel" { "Testing thread spawn and cancel"; let spawn_result = Thread::spawn(fn(){ "Thread running indefinitely..."; while true { } }); assert(spawn_result.is_ok(), "Thread spawn has failed"); let thr = spawn_result.unwrap(); let cancel_result = thr.cancel(); assert(cancel_result.is_ok(), "Thread cancel has failed"); }