do i need to use semaphore in AsyncUDP to be thread safe?

Hi,

Recently I am using the AsyncUDP lib (arduino-esp32/libraries/AsyncUDP at master · espressif/arduino-esp32 · GitHub) to receive UDP packet in async way. Not sure the detail of the lib, but I guess it use an separate thread to listen the inbound UDP packet and invoke the callback function. My doubt is, should I use semaphore in the callback function when I modify some global var value to be thread safe, if yes, should I use xSemaphoreTakeFromISR() or xSemaphoreTake()?

Thanks,
BR

When you use this xSemaphoreTake() in a ISR, expect to get a Guru Meditation error.

I'm not going to look at your code link, only you can determine if you need to protect a resource and need a semaphore.

Personally, in the callback, I'd have minimal code and instead pass the incoming info, to a parsing routine, triggered by an event trigger and reset the callback for the next interrupt.

Idahowalker:
When you use this xSemaphoreTake() in a ISR, expect to get a Guru Meditation error.

I'm not going to look at your code link, only you can determine if you need to protect a resource and need a semaphore.

Personally, in the callback, I'd have minimal code and instead pass the incoming info, to a parsing routine, triggered by an event trigger and reset the callback for the next interrupt.

Thanks for your advice. I understand that I need to use xSemaphoreTakeFromISR() in an ISR. But the things is I am not sure the detail implementation of the AsyncUDP lib, whether it's ISR or normal task.

If you assign the callback the IRAM_ATTR, freeRTOS will treat the callback as a ISR.

Idahowalker:
If you assign the callback the IRAM_ATTR, freeRTOS will treat the callback as a ISR.

Thanks!