All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Use of condition vars
@ 2011-12-29 20:39 Terry Fryar
  2011-12-29 23:56 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 3+ messages in thread
From: Terry Fryar @ 2011-12-29 20:39 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

Using Xenomai 2.6.0, I have a question regarding the use of condition
variables.  I think I understand why the mutex is required, but how to use
it is a bit of a mystery?
 
- To call "rt_cond_signal()", do you have to have the mutex acquired??
 
- I assume to call "rt_cond_wait()", you are required to have the mutex
acquired, yes??
 
So, the pseudocode would be:
 
Task1:
.
.
rt_cond_signal()
.
.
 
Task2, Task3, ....TaskN
.
.
rt_mutex_acquire()
while (rt_cond_wait() != 0)
// got it, do code that accesses the signaled var (mutex protected)
rt_mutex_release()
.
.
.
 
 
Is that it??

[-- Attachment #2: Type: text/html, Size: 3109 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Use of condition vars
  2011-12-29 20:39 [Xenomai-help] Use of condition vars Terry Fryar
@ 2011-12-29 23:56 ` Gilles Chanteperdrix
  2012-01-02 14:03   ` Terry Fryar
  0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2011-12-29 23:56 UTC (permalink / raw)
  To: Terry Fryar; +Cc: xenomai

On 12/29/2011 09:39 PM, Terry Fryar wrote:
> Using Xenomai 2.6.0, I have a question regarding the use of condition
> variables.  I think I understand why the mutex is required, but how to use
> it is a bit of a mystery?
>  
> - To call "rt_cond_signal()", do you have to have the mutex acquired??
>  
> - I assume to call "rt_cond_wait()", you are required to have the mutex
> acquired, yes??

You have to hold the mutex both for rt_cond_signal() and rt_cond_wait().
The following exercpt from linuxthreads man pages explains it:

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Use of condition vars
  2011-12-29 23:56 ` Gilles Chanteperdrix
@ 2012-01-02 14:03   ` Terry Fryar
  0 siblings, 0 replies; 3+ messages in thread
From: Terry Fryar @ 2012-01-02 14:03 UTC (permalink / raw)
  To: 'Gilles Chanteperdrix'; +Cc: xenomai

Thanks Gilles!

-----Original Message-----
From: Gilles Chanteperdrix [mailto:gilles.chanteperdrix@xenomai.org]
Sent: Thursday, December 29, 2011 5:56 PM
To: Terry Fryar
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Use of condition vars

On 12/29/2011 09:39 PM, Terry Fryar wrote:
> Using Xenomai 2.6.0, I have a question regarding the use of condition
> variables.  I think I understand why the mutex is required, but how to
> use it is a bit of a mystery?
>
> - To call "rt_cond_signal()", do you have to have the mutex acquired??
>
> - I assume to call "rt_cond_wait()", you are required to have the
> mutex acquired, yes??

You have to hold the mutex both for rt_cond_signal() and rt_cond_wait().
The following exercpt from linuxthreads man pages explains it:

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-02 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-29 20:39 [Xenomai-help] Use of condition vars Terry Fryar
2011-12-29 23:56 ` Gilles Chanteperdrix
2012-01-02 14:03   ` Terry Fryar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.