简体   繁体   English

为什么boost :: thread :: join如此昂贵?

[英]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). 我最近才开始使用boost::thread进行多线程工作,但我仍然不清楚一些细节,但是据我了解,当您希望“父”线程阻塞并等待时,使用thread::join 。完成线程(我敢肯定还有很多,但是我相信这是一种用途)。

In the program I'm working on, I have a thread load a bunch 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. 主线程等待此状态,然后调用join ,但取消阻塞似乎需要2秒钟。

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. 您看到的等待时间大概是由孩子在通知父母后在孩子中进行的其他工作或在轮询孩子的通知而在父母中进行的其他工作造成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM