Difference between SemaphoreHandle_t and critical section in esp-idf
Posted: Sat Jul 24, 2021 11:17 pm
Hello All,
I am fairly new to esp-idf and seeking information about a difference between semaphores and
critical sections in esp-idf. Digging through online posts, the only difference I found so far is that critical sections disable interrupts when protecting shared resources, and semaphores do not. What else should I be aware of?
A related Question #2 -- I need to implement some reference counting for my objects. I cannot use shared_ptr because it does not play well with freertos queues, and I also need write access to the reference counter. What would be the best way to implement atomic read-modify-write on an uint32 value? On esp32, reads and writes to uint32_t are atomic, but not RMW operation. Should I use freertos semaphore or a critical section? My objects are not accessed in ISRs.
Thank you in advance.
I am fairly new to esp-idf and seeking information about a difference between semaphores and
critical sections in esp-idf. Digging through online posts, the only difference I found so far is that critical sections disable interrupts when protecting shared resources, and semaphores do not. What else should I be aware of?
A related Question #2 -- I need to implement some reference counting for my objects. I cannot use shared_ptr because it does not play well with freertos queues, and I also need write access to the reference counter. What would be the best way to implement atomic read-modify-write on an uint32 value? On esp32, reads and writes to uint32_t are atomic, but not RMW operation. Should I use freertos semaphore or a critical section? My objects are not accessed in ISRs.
Thank you in advance.