File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -374,8 +374,25 @@ class PoliticianSense {
374374
375375 /* *
376376 * @brief Detaches from the engine and clears its packet logger.
377- * Call before destroying a PoliticianSense that was attached to a still-running engine,
378- * or to hand the packet logger slot back to the user.
377+ *
378+ * Sets _active = false first so any _onPacket() invocation already in flight
379+ * on the engine worker task will bail out immediately without touching members.
380+ * Then clears the engine's packet logger slot so no further calls are dispatched.
381+ *
382+ * @warning This does NOT provide a hard synchronisation barrier. If the engine
383+ * worker task has already passed the `if (!_active)` guard before end() writes
384+ * the flag, it may still access members after end() returns. This window is
385+ * narrow but real on a multi-core ESP32.
386+ *
387+ * Safe usage pattern when destroying from a different core/task:
388+ * @code
389+ * sense.end();
390+ * delay(20); // > one engine tick — guarantees any in-flight call has returned
391+ * // now safe to destroy or reuse
392+ * @endcode
393+ *
394+ * Calling end() from the same task/core as the engine worker (e.g. in loop())
395+ * is always safe with no delay required.
379396 */
380397 void end () {
381398 if (_engine) {
You can’t perform that action at this time.
0 commit comments