Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Periodic Scheduling with Linux pthreads

583 views
Skip to first unread message

Jim Shelton

unread,
Sep 26, 2001, 8:49:55 AM9/26/01
to
Im new to pthreads but think I have a good understanding of them. But I cant
seem to find a way to set up a thread to run periodically. For example at
20Hz. I think I know a way to do this through syncing with a RTAI (real time
kenel) that has periodic scheduling. But I cant find anything in the help
that allows me to run a thread every 50ms.

Ive looked at nanosleep() but I believe this puts the whole process to sleep
(All threads).

thanks for any help

Jim Shelton


force

unread,
Sep 26, 2001, 9:44:51 AM9/26/01
to
Jim Shelton <mjsh...@erols.com> wrote:

: Ive looked at nanosleep() but I believe this puts the whole process to sleep
: (All threads).

wrong. nanosleep() only puts the calling thread to sleep. You need to
consider that your thread/process may often be context switched out by
the kernel and you can't guarentee that your thread will always run
every 50ms.

If you need to guarantee this, get a dead-line monotonic RTOS.

--
Cheers.

Mark Johnson

unread,
Sep 26, 2001, 9:49:12 AM9/26/01
to
Jim Shelton wrote:

Well, as with anything on Unix (Linux), there are several ways to do this.
- wait for a duration (nanosleep/sleep/usleep)
- interval timers (setitimer/getitimer)
- busy wait, read the clock (gettimeofday)
Most of the timing benchmarks I've seen use nanosleep - I'm pretty sure that
can meet your need if coded carefully. Make sure you don't drift in the timing
routine, the errors tend to accumulate faster than you expect.

We have software that must run on a variety of platforms (development machines,
machines w/ IRIG-B time synchronization, etc.) so we tend to package the timing
stuff into a separate application & signal the real time task when its time to
wake up. That is a pretty heavy interface to support - I'd suggest one of the
other solutions based on what your needs are.
--Mark


0 new messages