+ 2

Thread and core with context switching

Hi I am not from ce background... I am aware on multi threading. Can anyone explain me that multi threading does not guarantee to put thread on different core What does this mean ? Also what is context switching?

1st May 2021, 12:42 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 1
( I will try to keep it as simple as possible, avoiding technical terms as much as I can. If you want more detailed info about it then do check the links attached with the answer ) There are 2 ways to do two(or more) tasks by the system at the same time. 1) using 2 completely different cores to do different processes parallelly. 2) scheduling those processes on single cpu core such that it looks like the process is taking place concurrently. If the second method is chosen then in order to switch from one thread to another, system need to know the state of that task so that it can resume it afterwards. This process of storing the state of that thread or process is known as context switching. For more info visit these links :- 1) https://en.wikipedia.org/wiki/Multithreading_(computer_architecture) 2) https://en.wikipedia.org/wiki/Context_switch
1st May 2021, 3:24 PM
Arsenic
Arsenic - avatar
+ 1
Thanks Arsenic . It is crisp and clear... Also tried to go through detailed information in the articles but could digest a bit. Is these two points in our control as programmer or not in our hand? Does it only maintained by system cpu ? Should we take care of any thing ?
1st May 2021, 7:05 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Ketan Lalcheta it's OS scheduler who controls whether a thread would be executing on same processing unit or on another. you can set thread affinities (which are requests to the OS to schedule a thread preferably on a certain core ) in your program, but the OS would be the ultimate decider.
2nd May 2021, 12:51 AM
Arsenic
Arsenic - avatar