How multithreading works on multicore cpu in linux..? [closed]

Posted on

Problem :

In one interview I got one question, If I have dual core cpu,can I run one thread on both CPU at a time? If possible how it is works.?

Solution :

A thread is an “atomic” unit in terms of process management. As such, you can’t run one thread on multiple cores in a sense that more than one core works on the thread at the same time.

But of course, a program (process) might span two or more threads which are exactly doing the same, or even duplicate a thread including all state and memory it currently has and let the copy run as an own, new thread. Multiple threads (whether or not they are doing exactly the same thing, access identical memory contents and have the same state) can (and likely will) run on different cores if possible.

This is not to be confused with thread relocation. The O/S might move a certain thread from the core where it currently runs to another core at any time for certain reasons (e.g. energy management). In that sense, one thread is likely to use multiple cores, but it still does not use more than one core at the same time; instead, it will “jump” from one core to another, using one core at any given point in time.

(To keep things simple, I did not distinguish Hyperthreading from real cores in the explanation above; I think this is OK in this context.)

Leave a Reply

Your email address will not be published. Required fields are marked *