Thread safety

Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Thread safety

Postby permal » Mon Jun 26, 2017 7:31 pm


I'm looking for information regarding thread safety in ESP-IDF.

For example, is it safe to to call esp_wifi_*, tcpip_adapter_* and other IDF APIs from the callback given to esp_event_loop_init()? Likewise, is it safe to call them from a FreeRTOS-thread?

The only information I've found re. this topic are the hits when [url? ... ea=default]searching the docs[/url], which only mentions that the I2C API and sdmmc_host_init() are not thread safe. Not quite the amount of information I was hoping for.



Posts: 2182
Joined: Sun May 08, 2016 4:11 am

Re: Thread safety

Postby ESP_Angus » Mon Jun 26, 2017 11:49 pm

Yes, both the APIs you mention are thread safe (they queue requests onto different tasks as necessary.) They can be called from event callbacks or from any other task (do not call them from interrupt context.)

In general, you should be able to assume an IDF API is thread-safe unless explicitly marked otherwise.

Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: Thread safety

Postby permal » Tue Jun 27, 2017 5:09 pm

Ok, thank you.

May I suggest adding that last sentence to the docs?

Posts: 20
Joined: Tue Sep 10, 2019 7:22 am

Re: Thread safety

Postby GreenGiant » Thu Dec 05, 2019 8:44 am

This might be a daft question, not my field of expertise. Is the same true for core safe; i.e. two threads running on different cores of the ESP32 with pre-emption in mind etc?

Posts: 3914
Joined: Thu Nov 26, 2015 4:08 am

Re: Thread safety

Postby ESP_Sprite » Fri Dec 06, 2019 2:04 am

Yes. In general, thread safe also implies multicore threading safe on SMP systems, including the ESP32.

Who is online

Users browsing this forum: No registered users and 30 guests