为什么我们应该在线程中使用Join? [英] Why we should use Join in threads?

查看:115
本文介绍了为什么我们应该在线程中使用Join?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个线程T1和T2,两个都有不同的工作,所以我们通常更喜欢通过线程连接来完成这个任务。

I have 2 threads T1 and T2 ,both have different jobs so usually we prefer to accomplish this task by thread Joins.

但我们可以使用join()完成此操作。我们可以在T1线程中添加T2线程的代码。
这有什么区别?

But we can do this with out using join(). We can add T2 thread's code inside T1 thread. What difference does this make ?

推荐答案

主要区别在于我们用T1加入T2线程,时间T2正在执行的工作也可以被T1利用,这意味着他们会做出不同的工作。但是当你在T1线程中包含T2线程代码时,这不会发生。

The main difference is when we join T2 thread with T1 ,the time T2 is executing the job can be utilised by T1 also ,that means they will do different job parllely.But this cann't happen when you include the T2 thread code inside T1 thread.

这篇关于为什么我们应该在线程中使用Join?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆