For some RTOS's, there is some event, or even a callout function that is called when the kernel is switching into, or even switching out of a thread. In pSOS it was called the TaskSwitchCallout. In this we would have code to increment counters whereby we knew how much CPU time a thread was taking. In Qnx, you can subscribe to an event that occurs when the kernel has switched in a task and perform the same counter increment.
Is there an equivalent in Windows? Often under Windows we cannot determine when exactly a thread context has been switched in or out of relative to other threads running in the system (read:managed code).
Please don't ask why I'm trying to do this, I can't talk about it. However I can say that the context switch counter in Windows perfmon is not sufficient. But I figure that the context switch counter in perfmon must get it's information from somewhere... I'm trying to access that somewhere on a per thread basis.
Thanks!!
Windows does not notify threads of context switches.
If you want timing information, use GetThreadTimes or QueryThreadCycleTime, or one of the performance counters.
Alternatively, you could make use of the Windows 7 User-mode scheduler, so you are in charge of the context switches: User-mode scheduling