You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on mbed RTOS and I realized that there is no document about condition variable. Do you support or is there any document about how to implement condition variable in mbed os? I tried searching but there was almost no document about it.
@c1728p9 put up a pr to add a ConditionalVariable class, though it ended up dropped: #3648
For most cases, condition variables can be replaced with the EventFlags class (here), although synchronization needs to be handled seperately. The documentation should be updated with the 5.6 release which is on the way, but for now there is just the doxygen in the header file.
Here's a simple example:
EventFlags flags;
Mutex mutex;
bool condition = false;
voidwait_for_condition() {
mutex.lock();
while (!condition) {
mutex.unlock();
flags.wait_any(1);
mutex.lock();
}
mutex.unlock();
}
voidtrigger_condition() {
mutex.lock(); // note, we don't need this mutex if we are in interrupt context
condition = true;
flags.set(1);
mutex.unlock();
}
Thank you very much for you reply, I guess EventFlags is good as a replacement for ConditionalVariable. Still hope that one day ConditionalVariable would be reopened
Activity
geky commentedon Sep 11, 2017
Good thing to notice
@c1728p9 put up a pr to add a ConditionalVariable class, though it ended up dropped: #3648
For most cases, condition variables can be replaced with the EventFlags class (here), although synchronization needs to be handled seperately. The documentation should be updated with the 5.6 release which is on the way, but for now there is just the doxygen in the header file.
Here's a simple example:
Here's a real world example where we use event flags as condition variables in the socket classes:
https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/UDPSocket.cpp#L76
DuyTrandeLion commentedon Sep 12, 2017
Thank you very much for you reply, I guess EventFlags is good as a replacement for ConditionalVariable. Still hope that one day ConditionalVariable would be reopened
kjbracey commentedon Nov 14, 2017
#3648 has now been merged, so
rtos::ConditionVariable
is present on master, and will be in mbed-os-5.7.