> -----Original Message-----
> From: Steven Seeger
> Sent: Sunday, February 03, 2008 12:01 PM
> To: 'Gilles Chanteperdrix'
> Subject: RE: [Xenomai-help] periodic task question
> 
> I guess I don't see the difference here. I lock the mutex first, and
then
> wait on the conditional. The only time that conditional is ever
signaled
> is after something else sets playing to non-zero. (This code actually
> clears playing after locking that mutex, however I didn't put that in
> here.)
> 
> What may be causing the problem is the other person who is locking
> sound_mutex is a non-realtime thread via write ops for a character
device.
> Oops. Perhaps I need a new method for this. :) (rt_mutex_acquire() is
> returning -1.)
> 
> Steven
> 
> > -----Original Message-----
> > From: Gilles Chanteperdrix [mailto:[EMAIL PROTECTED]
> > Sent: Sunday, February 03, 2008 11:54 AM
> > To: Steven Seeger
> > Subject: RE: [Xenomai-help] periodic task question
> >
> > Steven Seeger wrote:
> >  > This is the relevant code. In aperiodic mode, it works fine. In
> > periodic
> >  > mode (125us timebase) then when I activate this task by sending
data
> to
> >  > /dev/dsp the sound plays very fast and then the watchdog kills
the
> >  > thread. If I change this to set the period only after
rt_cond_wait()
> >  > returns, it works fine.
> >  >
> >  > static void sound_func(void *data)
> >  > {
> >  >     rt_task_set_periodic(&sound_task, TM_NOW,
> >  > rt_timer_ns2ticks(ST_AUDIO_PERIOD));
> >  >
> >  >     for (;;) //go until suspended or thread deletion
> >  >     {
> >  >  if(!playing) {
> >  >             rt_mutex_acquire(&sound_mutex, TM_INFINITE);
> >  >             rt_cond_wait(&sound_cond, &sound_mutex, TM_INFINITE);
> >  >             rt_mutex_release(&sound_mutex);
> >  >         }
> >
> > This code is wrong, it should be:
> >
> > rt_mutex_acquire(&sound_mutex, TM_INFINITE);
> > while (!playing)
> >         rt_cond_wait(&sound_cond, &sound_mutex, TM_INFINITE);
> > rt_mutex_release(&sound_mutex);
> >
> > Here is the relevant doc of pthread_cond_wait:
> >        A condition variable must always be associated with a mutex,
to
> > avoid
> >        the race condition where a thread prepares to wait on a
condition
> > vari-
> >        able and another thread signals the condition  just  before
the
> > first
> >        thread actually waits on it.
> >
> >
> > --
> >
> >
> >                                         Gilles Chanteperdrix.

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to