From fe6f9df7de8cbaa59fb8b4fed346321cc935d003 Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Thu, 10 May 2012 16:54:19 -0700 Subject: [PATCH] Add example of detached threads and a warning about GC joining joinable thread if they haven't been joined. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index c0155f3..ded46df 100644 --- a/README.md +++ b/README.md @@ -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. +