Open wirepair opened 1 year ago
🤔
I don't know very well this part of libuv
, so bear with me.
Is uv_thread_join
idempotent? That is, can I invoke it multiple times on the same thread?
I thought that was the case but I could be wrong and I can't find any reference to the libuv
documentation.
However, if this isn't the case, is there a function in libuv to know when a join
is needed and when it isn't because the thread has already returned?
CC @stefanofiorentino do you know how it works under the hood within libuv
?
CC @stefanofiorentino do you know how it works under the hood within
libuv
?
Let me check some internals..
@wirepair as in uvw we are leveraging the RAII pattern, the destructor of the of uvw::thread is already calling join, so currently you could not call it by yourself. @skypjack we can either put join private or create an invariant to avoid the second call to join in case the public join has been called. I guess giving the user the freedom to force a join is the way to go, do you agree?
Yeah, makes sense. A boolean member is enough for that probably. Not a big deal. 👍
Code to replicate:
Took me a while to debug, and only occurred when i had > 4 threads (???) but I get a segmentation fault since
join()
is being called twice (once by me, and once on exiting the main function scope). I'm not sure how we can call join if it's also apart of the destructor?Here's the backtrace: