POSIX timeout bogosity

September 26th, 2006 by pim

Grace uses pthread conditionals to facilitate communication between threads. Worker threads waiting for new events can either wait indefinitely for an event or sleep on it for a determined number of milliseconds. The latter is implemented using the pthread_cond_timedwait() call. And this is where design-by-committee has gone completely insane. Someone thought he was being clever and specified the resolution for this call to be set in nanoseconds. Just what you need if you want to trigger conditionals in your particle accelerator. A bit of a bummer, though, if you want to use this call in, you know, actual real world conditions.


To make matters worse, this same clever fellow also had the bright idea to let this call work on the basis of an alarm time, which seems to me like the less common scenario when dealing with functions that have a timeout. Even this would have been forgivable, but the only way to get a timespec with nanosecond resolution is the clock_get() function, which is only available on systems that implement real time. Unfortunately there are systems out there that do implement the pthread_cond_timedwait() call but lack clock_get(). By the time you have actually converted the current time (in microsecond resolution) to a timespec (with nanosecond resolution) and added your timeout interval, all of this nano-goodness has already lost its resolution.

Idiots.

Comments are closed.