且构网

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

什么是线程(什么是线程)?

更新时间:2021-10-19 23:25:31

一个简单的解释是您有工作要做,而只有一个人来完成工作.

A simple explanation would be that you have a job to do, and you get a single person to do the job.

此人类似于计算机中的线程.

This single person is similar to a thread in a computer.

一个人一次只能做一件事情,所以要完成这项工作,他会完成工作的各项任务,一次完成一项任务,一次完成一项任务.

One person can do one thing at a time, so to do the job, he proceeds through the tasks of the job, one task at a time, one operation on each task at a time.

要加快工作速度,您可以让更多人从事同一工作.例如,假设您需要粉刷一所房子.您雇了4个人来做这个.

To speed up a job, you can put more people to the same job. For instance, let's say you need to paint a house. You hire 4 people to do this.

这4个人可能与4个线程相似,因为他们使用相同的资源(相同的房子,相同的油漆桶)工作,并且可以将工作分开.

These 4 people could be similar to 4 threads in that they work with the same resources (same house, same buckets of paint) and they can divide up the work.

一个过程类似于粉刷那所房子的工作.

A process would be akin to the job of painting that house.

对于没有足够的CPU内核来同时运行所有线程的机器,这种简单的解释有些混乱,但是在这里我将忽略它.

This simple explanation somewhat breaks down when it comes to machines that doesn't have enough CPU cores to run all the threads simultaneously, but I'm going to ignore this here.