如何实现pthread_join? [英] How is pthread_join implemented?
本文介绍了如何实现pthread_join?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对线程技术还是有点陌生,所以您必须原谅这个问题的天真.
I'm a little new to threading, so you'll have to forgive the naiveté of this question.
pthread_join
的实现方式如何影响线程调度?
How is pthread_join
implemented and how does it effect thread scheduling?
我总是想像pthread_join
是用while循环实现的,只是使调用线程屈服直到目标线程完成.像这样(非常近似的伪代码):
I always pictured pthread_join
implemented with a while loop, simply causing the calling thread to yield until the target thread completes. Like this (very approximate pseudocode):
atomic bool done;
thread_run {
do_stuff();
done = true;
}
thread_join {
while(!done) {
thread_yield();
// basically, make the thread that calls "join" on
// our thread yield until our thread completes
}
}
这是一个准确的描述,还是我大大简化了流程?
Is this an accurate depiction, or am I vastly oversimplifying the process?
干杯!
推荐答案
Yes that's the general idea. For gory details of a particular implementation take a look at glibc.
这篇关于如何实现pthread_join?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文