|
|
Question : how to schedule threads for time
|
|
Hi I'm using pthreads. I've have not been able to find a examples showing how to schedule thread execution based on time. For example if i want a thread to run every 100ms. Can anyone point me to some good example code.
|
Answer : how to schedule threads for time
|
|
This is typically done by having the thread's run routine be a loop that sleeps for 100ms on each iteration:
while(1) { pthread_testcancel(); do_some_work(); usleep(100000); }
If your system does not support a thread-safe usleep, you could use pthread_cond_timedwait() instead by createing a private condition variable that noone will ever signal.
|
|
|
|