Hi Edgar,

To suspend a periodic task until the next cycle I use the construct:

void *fun(void *arg)
{
    while(1) {
        pthread_wait_np();
        // wakeup and do stuff
    }
}

NOTE: the pthread_wait_np() should be at the begining of your loop,
otherwise you will run 1 pass (almost) immediately you do the
pthread_create for the task.

I'm a little confused why the call is called pthread_wait_np(), as it
seems to be a replacement for the old rt_task_wait() and nothing to do
with the POSIX pthread API.

If you want to put a POSIX thread to sleep until some event occurs, the
conventional method is to block on the aquisition of a mutex:
pthread_mutex_lock(&mut) or wait on a condition variable
pthread_cond_wait(&cond, &mut).  The best reference I have found for
this stuff is 'Programming with POSIX Threads', David R. Butenhof ISBN
0-201-63392-2

Regards, Stuart


Edgar F. Hilton wrote:
> 
> Question:
> 
> According to the man pages of pthread_suspend_np:
> 
>  "Note: the thread is not guaranteed to be suspended immediately."
> 
> If this is the case (as it certainly seems to be), then how the heck do I stop 
>program execution until the next time that I call "pthread_make_periodic_np"?
> 
> I have tried:
> 
> phtread_suspend_np(pthread_self());
> 
> and even:
> 
> pthread_suspend_np(pthread_self());
> pthread_wait_np();
> 
> but either of these do not seem to work too well either (it stops the
> task from running over one cycle, however since pthread_suspend_np
> does not seem to have taken effect yet, the task continues to be
> called at every period). Should I exit the tasks entirely and somehow
> recreate them on the next time around? Should I add delays???
> 
> HELP!! I am really stuck.

--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/

Reply via email to