I have 1 Question put by customer peer..
He is writing his own program for task-switching of threads, infact he has already coded completely using Win32 API's, like Set/GetContext, DumpStack, Suspend/ResumeThread,
Currently, it crashes under certain situations only, probably in places where register is not getting proper value when stack context is dumped back for execution..
At this point, he does not want to go into details of his self-written code, just want a high-level answer (may be like a sequence/event flow, or process flow, or probably few
assembly tricks may be)..
Suppose I have some background thread, Tb, doing monitoring threads work, for simplicity, 1 thread T1 ..
T1 is doing work 1-2-3-4-5-6-7-8 in sequence..
At some point T1 is executing work 3 .. Tb needs T1 to suspend work 3, instead carry out 8, and after finishing jump back to original work 3 ..
1. Tb suspends T1, so now work 3 is suspended..
2. Default I think is __fastcall, so Tb will save callee function registers, do stack cleanup etc.. instead of self-cleanup by callee..
--> plz correct if its wrong..
3. Tb sets/saves context , and T1 has to do work 8..
-> How will Tb setup T1 to do work 8, and get the saved context/registers back and jump T1 to work 3 to finish the further works, gracefully..
In 3., there are lot of problems that would come, related to Suspending/Resuming Thread T1, context-restores, so that if any of original register values are not set properly,
runtime crash will occur ..
putting another way, he wants to know how 1 thread can read the register values (say rip, rax, rcx) of another thread, and set it back to proper values.. i.e, doing save/restore explicitly by some means?
If user-code is needed to examine, I can zip the source and attach here for analysis..