[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Peter Wang wrote:
PS. we're not talking about timers (they're in a different thread)
Having looked at the thread and timer code, I see what you mean now. So
this background manager thread is supposed to run at a fixed rate, and
the rate seems to have something to do with Allegro's (DOS-based) timer
speed..
If this bg thread is supposed to run 100 times a second, then why not do
this for the main loop:
gettimeofday(&new_time, 0);
interval += ((new_time.tv_sec - old_time.tv_sec) * 1000000L +
(new_time.tv_usec - old_time.tv_usec));
old_time = new_time;
while (interval > 10000) {
interval -= 10000;
pthread_mutex_lock(&cli_mutex);
/* etc */
pthread_mutex_unlock(&cli_mutex);
}
delay.tv_sec = 0;
delay.tv_usec = 1;
select(0, NULL, NULL, NULL, &delay);
pthread_testcancel();
That'll run each background thread 100 times a second (once every 10,000
usecs), compensate for execution time jitter, and maintain
sub-millisecond accuracy. I could probably test this myself.
- Kitty Cat