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;