且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

线程终止问题(C语言编程)

更新时间:2021-06-27 21:15:41

是的,你应该加入的线程。 加入一个线程仅仅意味着等待,直到线程终止。换句话说,你会怎么做。

Yes, you should "join" the threads. "Joining" a thread simply means waiting until the thread has terminated. In other words, you would do

pthread_join(tid1, NULL);
pthread_join(tid2, NULL);

要等到这两个线程都终止。

to wait until both threads have terminated.

编辑:如果你有一个子线程,这反过来,创建了一个孙子线程怎么办?作为一项规则,谁创建线程应该等待它终止(加入的话)。因此,在这种情况下,子线程会叫phtread_join孙子线程,而主线程会召唤加盟子线程上。

What to do if you have a child thread which, in turn, creates a "grandchild" thread? As a rule, whoever created the thread should wait for it to terminate ("join" it). So in this scenario, the child thread would call phtread_join on the grandchild thread, and the main thread would call join on the child thread.