Conditional Variables in FreeRTOS

rileypack wrote on Tuesday, June 01, 2010:


I’ve been using FreeRTOS to implement a project that would be significantly easier to complete with conditional variables.  Has anyone implemented this with FreeRTOS or is there already support for it that I missed?

davedoors wrote on Wednesday, June 02, 2010:

Can you say what you want to achieve with the CV? It might be that you could use a binary semaphore or mutex to do the same

teelarmas wrote on Thursday, February 02, 2017:

Any update on this? I’m looking to update an open source project that requires direct access to CV’s to be compatible with my FreeRTOS system.

rtel wrote on Friday, February 03, 2017:

The reply can be the same as the last unanswered reply, expect we can
add direct to task notifications and event groups to the previous
mentions of semaphores and mutexes. Really though, can’t answer the
question unless somebody says what they are trying to achieve - the last
time this was asked was six years ago.

jacobschloss wrote on Friday, December 28, 2018:

I took a stab at an implementation, posted here based on this paper from MS Research. (It won’t run yet, lets call it a reference for now : ) ), it is bascially the C# code from the WIN32 section at the end of the paper ported to c++. According to the MS paper, this method can work however, on OS that do not provide an atomic “unlock this primative while locking this other primative”.

For me at least, I would like to provide a mostly C++11 compliant thread primatives implemented on FreeRTOS. I find the CV style useful when writing certain kinds of code, and would like to keep using it. I have also wanted to implement pthreads for freertos, which also needs a CV primative.

The paper was very interesting. If there was a way to atomically unlock & lock two objects, or unlock an object & suspend a task, or unlock a lock and enqueue built into the kernal/task API this would be a lot easier (and higher performance). Unlock mutex / suspend task might be easiest.

jacobschloss wrote on Friday, December 28, 2018:

There are some issues using a waiter-LIFO, like I implemented, in an RTOS setting. Perhaps sorting by priority on enqueue would be required, otherwise there could be a priority inversion.