Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is context switching of threads done on a multi-core processor?

Tags:

People also ask

How does context switching work for threads?

Process context switching takes place when the operating system's scheduler saves the current state of the running program(current process) (including the state of PCB) and switches to another process whereas Thread context switching takes place when the CPU saves the current state of the thread and switches to another ...

What is context switching in multi threaded application?

A context switch (also sometimes referred to as a process switch or a task switch) is the switching of the CPU (central processing unit) from one process or thread to another.

How is a context switch performed?

A context switching is a process that involves switching of the CPU from one process or task to another. In this phenomenon, the execution of the process that is present in the running state is suspended by the kernel and another process that is present in the ready state is executed by the CPU.

How does a multi-core processor work?

A multicore processor is an integrated circuit that has two or more processor cores attached for enhanced performance and reduced power consumption. These processors also enable more efficient simultaneous processing of multiple tasks, such as with parallel processing and multithreading.


When doing context switching on a single-core processor, the code responsible is executed on the only CPU which takes care of switching the threads.

But how is this done when we have multiple CPUs? Is there a master CPU which does all the context switching of all slave CPUs? Is each CPU responsible for its own context switching? If so, how is the switching synchronized so that two CPUs are not executing the same thread? Or is there some other mechanism in place?