Page 1 of 1

C++11 threads

Posted: Thu Sep 20, 2018 9:22 am
by PeterR
I have a third party library I would like to include into an my ESP-IDF project.
The library uses C++ threads, mutex etc.

My FreeRTOS task would call a library function. The library function would block on a C++11 mutex before sending to a C++ queue. A C++ thread would use the mutex to gain the queue and service.
The FreeRTOS task may therefore be blocked by a C++ mutex held by a C++ thread.

How is C++ threading integrated within the ESP-IDF? I assume that the native implementation is FreeRTOS?
Will .native_handle() return the FreeRTOS equivalent?

Has anyone used C++ threads in ESP-IDF. Are these features stable?

Re: C++11 threads

Posted: Thu Sep 20, 2018 2:31 pm
by ESP_igrr
C++ threading is implemented on top of pthreads (that's the standard implentation in libstdc++v3) which in turn is implemented on top of FreeRTOS in ESP-IDF.
So all threads (pthreads, c++11 threads) are actually FreeRTOS threads, just wrapped with some levels of indirection. Same applies to mutexes. Therefore blocking a FreeRTOS thread on a c++11 mutex is not a problem.

native_handle should return a pointer to a pthread.

Re: C++11 threads

Posted: Thu Sep 20, 2018 8:45 pm
by fly135
I ported some code over that uses pthreads and it works. However, I'm converting it over to use FreeRTOS threads simply because adding an adaptation layer leaves me wondering what might go wrong.

John A

Re: C++11 threads

Posted: Fri Sep 21, 2018 10:28 am
by PeterR
ESP_igrr wrote:native_handle should return a pointer to a pthread.
Which is a FreeRTOS task handle? That is to ask if I could use that handle directly to change priority etc?

Re: C++11 threads

Posted: Fri Sep 21, 2018 4:09 pm
by ESP_igrr
No, that's an internal structure which contains the handle: https://github.com/espressif/esp-idf/bl ... read.c#L51