C++11 threads

PeterR
Posts: 33
Joined: Mon Jun 04, 2018 2:47 pm

C++11 threads

Postby PeterR » Thu Sep 20, 2018 9:22 am

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?

ESP_igrr
Posts: 1142
Joined: Tue Dec 01, 2015 8:37 am

Re: C++11 threads

Postby ESP_igrr » Thu Sep 20, 2018 2:31 pm

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.

User avatar
fly135
Posts: 391
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: C++11 threads

Postby fly135 » Thu Sep 20, 2018 8:45 pm

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

PeterR
Posts: 33
Joined: Mon Jun 04, 2018 2:47 pm

Re: C++11 threads

Postby PeterR » Fri Sep 21, 2018 10:28 am

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?

ESP_igrr
Posts: 1142
Joined: Tue Dec 01, 2015 8:37 am

Re: C++11 threads

Postby ESP_igrr » Fri Sep 21, 2018 4:09 pm

No, that's an internal structure which contains the handle: https://github.com/espressif/esp-idf/bl ... read.c#L51

Who is online

Users browsing this forum: mojesp32s and 5 guests