Define _TASK_THREAD_SAFE for TaskScheduler #1598
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I appreciate the use of TaskScheduler as an alternative to extending the
loop()
approach.To make further use of TaskScheduler's features, it makes sense to me to change task scheduling intervals dynamically at runtime. Example: The MQTT loop is executed at a specific interval, the MQTT publish interval. Once the user changes this interval, the scheduling interval of the MQTT loop should be changed accordingly. The straight-forward approach is to call
setInterval()
in the respective web server handler. That will execute in the web server's context. Changing TaskScheduler task properties from another context is not inherently save.In
platformio.ini
, thebuild_flags
should use-D_TASK_THREAD_SAFE
to enable the use of an internal mutex which prevents unexpected behavior once multiple threads (FreeRTOS tasks) start changing task or scheduler settings.An excerpt from the TaskScheduler docs:
The author suggests to define this flag when using TaskScheduler on ESP32.