Use of condition vars
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??
Quoted 8 lines · Terry Fryar
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.
Signature · 1 line
Gilles.
Thanks Gilles!
-----Original Message-----
From: Gilles Chanteperdrix [mailto:[email protected]]
Sent: Thursday, December 29, 2011 5:56 PM
To: Terry Fryar
Cc: [email protected]
Subject: Re: [Xenomai-help] Use of condition vars
Quoted 8 lines · Terry Fryar
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.