Add example of detached threads and a warning about GC joining joinable thread if they haven't been joined.

master
Robert G. Jakabosky 14 years ago
parent 45587ff545
commit fe6f9df7de

@ -58,10 +58,21 @@ Example usage
return ...
]]
-- create detached child thread.
local thread = llthreads.new(thread_code, "number:", 1234, "nil:", nil, "bool:", true)
-- start non-joinable detached child thread.
assert(thread:start(true))
-- Use a detatched child thread when you don't care when the child finishes.
-- create child thread.
local thread = llthreads.new(thread_code, "number:", 1234, "nil:", nil, "bool:", true)
-- start joinable child thread.
assert(thread:start())
-- Warning: If you don't call thread:join() on a joinable child thread, it will be called
-- by the garbage collector, which may cause random pauses/freeze of the parent thread.
print("PARENT: child returned: ", thread:join())
local socket = require"socket"
socket.sleep(2) -- give detached thread some time to run.

Loading…
Cancel
Save