freertos-addons
freertos-addons copied to clipboard
Why does Tasklet require a Mutex?
We're evaluating the freertos-c++ lib for possible usage. Can you explain why Tasklet involves a Mutex? That doesn't seem to be the typical usage pattern in the underlying FreeRTOS C implementation.
It's to protect against race conditions that might occur if/when the Tasklet is deleted. You can see an example usage in https://github.com/michaelbecker/freertos-addons/blob/master/Linux/Demo/Linux_g%2B%2B_tasklets/main.cpp
Thanks. By "deleted" do you mean "deleted from RAM via delete
operator"? Or "deleted from FreeRTOS Task List"?
Both. If you are using the C++ wrappers and you decide you want to permanently delete a Tasklet object, then you should be calling the delete operator, either directly or indirectly (like when a local object goes out of scope). Just make sure you include a call to CheckForSafeDelete() in your destructor to prevent any weird race conditions. In that code I've leveraging the semaphore/mutex again to guarantee FreeRTOS doesn't try to run your tasklet code after you've deleted it.