From e406a06f61c6bff7d666dc510ff74afa05fbbc3d Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Fri, 13 Feb 2026 13:40:45 -0500 Subject: [PATCH] Fix race condition in display refresh locking --- basic1.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/basic1.cpp b/basic1.cpp index 780600b..700710b 100644 --- a/basic1.cpp +++ b/basic1.cpp @@ -88,7 +88,7 @@ void core1_entry() { while (1) { // Wait for refresh request if (refresh_requested && refresh_buffer && refresh_display) { - refresh_in_progress = true; + // refresh_in_progress is already set by Core 0 to lock the buffer // Get local copies for safe access LowLevelDisplay* display = refresh_display; @@ -100,7 +100,7 @@ void core1_entry() { // Clear flags refresh_requested = false; - refresh_in_progress = false; + refresh_in_progress = false; // Unlock buffer for Core 0 } // Small delay to avoid busy-waiting @@ -124,6 +124,10 @@ bool refresh_screen_async(const uint8_t *buffer, LowLevelDisplay* display) { return false; } + // Lock the buffer immediately on Core 0 to prevent race condition + // Core 1 will unlock it (set to false) when done + refresh_in_progress = true; + // Queue refresh on Core 1 refresh_buffer = buffer; refresh_display = display;