Well, what I'm trying to do is to create several threads, sharing single memory region (without FIFO). One of those threads should always wait on the data in this region to be updated from other threads (and, let's say, send this data over serial upon update). Is this the case to use cond vars? Here is my approach:
Code: Select all
thread_t thread_that_sends_data_over_serial() {
while(true) {
chMtxLock(&Mtx);
chCondWait(&dataUpdated);
... perform blocking transmission ...
chMtxUnlock(&Mtx);
}
}
thread_t t1/t2/t3/t4...() {
while(true) {
... do something ...
chMtxLock(&Mtx);
... write data to the memory region ...
chCondSignal(&dataUpdated);
chMtxUnlock(&Mtx);
... do something ...
}
}
Am I right in assumptions, that:
1. thread_that_sends_data_over_serial will block on chCondWait until any single thread (t1/t2/t3 etc) will lock the mutex and execute chCondSignal?
2. threads t1/t2/t3 etc will not interfere - as soon as t1 will unlock the mutex, thread_that_sends_data_over_serial will lock it and prevent other threads from changing the data?
Again, sorry for newbie questions here...