What are Threads in Computer Processor or CPU?

Threads are the virtual components or codes, which divides the physical core of a CPU into virtual multiple cores. A single CPU core can have up-to 2 threads per core.

For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads. And if a CPU is Octal core (i.e., 8 core) it will have 16 threads and vice-versa.

Working:
The thread is created by a process. Every time you open an application, it itself creates a thread which will handle all the tasks of that specific application. Like-wise the more application you open more threads will be created.


The threads are always created by the operating system for performing a task of a specific application.
There is single thread (code of that core which performs the computations also known as primary thread) on the core which when gets the information from the user, creates another thread and allocates the task to it. Similarly, if it gets another instruction it forms second thread and allocates the task to it. Making a total of two threads.

Example:
The smartphone application is an example of this, when you open a app it shows a circle which spins continuously, this process is done by a thread created for this purpose only, and the second thread loads the information and presents it in the Graphical User Interface.

The only fact that will limit the creation of the threads will be the number of the threads provided by the physical CPU, and it varies from CPU to CPU. The 1st image is the loading spinner by the first thread and the second one is the GUI loading by the second thread.





Now, What is the use of a thread ?
Threads have become a vital part of the computing as they allow the processor to perform multiple tasks at the same time making the tasks faster. And also making the computer capable of multitasking. Due to threads only you are able to browse the web as well as listen to music simultaneously.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.