Why is boost::thread::join seemingly so expensive?
I just recently started working with multithreading with boost::thread
, and I'm still a little unclear about some details, but from what I understand, thread::join
is used when you want the 'parent' thread to block and wait for the thread to finish (I'm sure there's more to it than that, but I believe that is one use).
In the program I'm working on, I have a thread load a bun开发者_高级运维ch of resources, and then in the last line, set its status to 'finished'. The main thread waits for this status and then calls join
, but it seems to take about 2 seconds for it to unblock.
Is there a reason for this, or am I doing something wrong?
Surely it does not take two seconds to join a thread (assuming the system is not overloaded in general). The waiting time you're seeing is presumably caused by some other work being done either in the children after they notify the parent, or in the parent while it polls for notifications from the children.
精彩评论