Passing control to a thread immediately (immediate context switch)
Posted on 2010-11-25
I have been a multi-threading developer for years, but I don't know how to accomplish the following. Someone suggested "fibers" but I get enough of that in my diet already LOL.
In my main form, I have created a separate thread that runs all the time, spinning and waiting (with sleep(1) in the loop to throttle it a bit) for a global flag to be set before it performs its action. Once I set that flag to True to signal the tread to start it's processing, I notice it takes about 3-5 milliseconds for the thread to start doing it's thing. I need to eliminate this delay.
Using the process object, I have elevated my priority to high and when I create that thread, its priority is set to high as well to help assign horsepower.
This is probably the natural delay between the time the main form gives up it's quantum and the OS thread scheduler gets around to scheduling time for that target thread. I need to eliminate this delay since it's a real time need.
How do I effectively transfer control to that running thread right away without the delay mentioned above. (as if it were a called subroutine).