Multitasking and use of mutex

Electrik
Posts: 2
Joined: Sun Jun 21, 2020 1:11 pm

Multitasking and use of mutex

Postby Electrik » Sun Jun 21, 2020 1:19 pm

Hello,
I'm trying to get familiar with using multiple tasks on the Esp32 to avoid tasks blocking eachother. Now I understand that a mutex should be used when accessing the same resources, but it is not clear for me at what level that should take place.
Let's say there are three tasks:
- mqtt
- webserver
- general WiFi access

Al of them are using the WiFi resource at some point. Should a mutex be created that prevents accessing the WiFi resource, or is it on for example the mqtt level enough?

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Multitasking and use of mutex

Postby ESP_Sprite » Sun Jun 21, 2020 7:37 pm

'WiFi' itself is not a resource that you use directly; it is abstracted by other drivers in ESP-IDF, so you should look at the drivers to see if they need muxes. In general, you can assume that ESP-IDF drivers are re-entrant (meaning you can happily use them in different threads) unless the documentation says differently.

Electrik
Posts: 2
Joined: Sun Jun 21, 2020 1:11 pm

Re: Multitasking and use of mutex

Postby Electrik » Mon Jun 22, 2020 11:47 am

All right thanks. I will look into this.
Is this valid for the Arduino platform also?

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Multitasking and use of mutex

Postby ESP_Sprite » Tue Jun 23, 2020 7:52 am

Mostly; I'm not sure which APIs on the Arduino side are and aren't re-entrant, though.

Who is online

Users browsing this forum: No registered users and 116 guests