Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Are Threads (What is a Thread)?

I'm always confused about thread concepts. I haven't a chance to use them in a real environment so far. It would be helpful if someone could explain threads for me.

like image 322
leela Avatar asked Jul 08 '09 08:07

leela


1 Answers

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.

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.

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.

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.

like image 80
Lasse V. Karlsen Avatar answered Dec 09 '22 03:12

Lasse V. Karlsen