Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows Win32 Process
Hi,
 
At several places I have read,
 
Quote:
Each thread has its own set of CPU registers and its own stack

 
Here, I can understand about stack, it's a data structure. But how thread can have its own CPU registers. They are fix in number and there are limitless number of threads are running in the system.
 
Regards
Posted 29-Apr-12 2:33am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Because they are part of what is called the execution Context. Basically, when a thread is suspended for whatever reason, the current machine state (all registers, including program counter, stack pointer and flag values) are saves as part of the Context with the Thread. The actual machine registers are then free for other Threads to use. When a Thread is resumed, the Context is restored back to where it came from, and the Thread does not even have to be made aware that it was suspended.
 
If this didn't occur, then the actual registers would be shared, and one task could corrupt them for another. It would also not be possible to restart a Thread on a different Core or even physical processor!
  Permalink  
Comments
Pranit Kothari at 29-Apr-12 8:02am
   
Thanks. 5!
SAKryukov at 29-Apr-12 21:59pm
   
Correct, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 29 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100