Hello!
On Sun, Feb 9, 2014 at 1:53 AM, Bjørnar Ness wrote:
> In a application I am starting 5 threads, all return:
> {subsys="thread_name",status="some_status"}
>
> What I want to do is wait for the thread that exists first, and if it has a
> status other
> than "unknown", print a status status and ngx.exit(ngx.OK)
>
According to the current implementation (assuming your ngx_lua is up
to date), ngx.thread.wait() will automatically skip already waited
thread object in the arguments unless there is no thread to wait.
>
> Problem with this approach is I get "failed to wait: already waited"
This error is returned only when *all* the thread arguments are dead.
Please check if this is the case.
> If I could pass a table threads into wait, I could remove the finished
> thread (subsys), but this
> does not seem possible..
I'm going to add an ngx.thread.wait2() call which can be invoked like this:
local threads = { t1, t2, t3, t4 }
local n = #table
for i = 1, n do
local idx, res = ngx.thread.wait2(threads, n)
if idx then
threads[idx] = nil
end
end
> and perhaps also not safe if the thread exits when
> not waiting?
>
When the child thread exits before its parent waits on it (or exits),
the child thread becomes "zombie" and the results are preserved. The
parent can still later wait on "zombie" child threads and fetch its
results.
If you believe there is a bug in ngx.thread.wait(), please try to
provide a minimal and complete example that can reproduce this issue.
Thank you!
Best regards,
-agentzh