Could you recommend a good way to make a "real time" task manager using
threads for the tasks? I would like to be able to specify the desired
frequency that each thread is called, ie, from 1Hz to 10kHz. I am
thinking of using a central task manager thread for this which runs full
out polling the current time to determine when to start each thread.
That is not as efficient as an interrupt based task manager, but I'm not
sure if such a thing exists on Windows 7 at least.
I do not know about Windows 7, but at least for previous NT based
kernels _with_ multimedia timers enabled, 1 ms resolution (1 kHz) is
obtainable. In each thread, after the actual work has been done, get
the time stamp, calculate how long it takes, until the thread should
be restarted for the next time and use this for the timeout parameter
for the WaitForSingleObject() call.
To have some predictability, the thread should execute at some
priority in the real time priority class and the keyboard and mouse
ports should be plugged by glue to avoid any user interference .
Without enabling multimedia timers, the resolution is 10 ms (or 15.625
ms for multiprocessor boards).
For other multitasking OSs, run the hardware timer interrupt at 10 kHz
and activate the sleeping threads by activating an event flag (or what
ever it is called) or send a message to the thread sleeping and
waiting to be activated each time the reactivation time has occurred.
With lots of threads with different reactivation times, it makes sense
to have a clock queue with the next reactivation times in a sorted
list, thus you generally have to check only two reactivation times in
the ISR.