From 558132b72acafbe68985ceca2e3a595cac27d82f Mon Sep 17 00:00:00 2001 From: Vlad George Iftode <37593074+viftode4@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:36:20 +0000 Subject: [PATCH] Make concurrent_writer::continue_writing_ atomic wait() writes the flag from the calling thread while the worker thread reads it in its loop condition. ThreadSanitizer reports this as a data race on an idle writer. Co-Authored-By: Claude Sonnet 5.5 --- src/stan/callbacks/concurrent_writer.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stan/callbacks/concurrent_writer.hpp b/src/stan/callbacks/concurrent_writer.hpp index 959ba222510..faee38abaa6 100644 --- a/src/stan/callbacks/concurrent_writer.hpp +++ b/src/stan/callbacks/concurrent_writer.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -59,7 +60,7 @@ struct concurrent_writer { // Threshold where the writing threads will wait for the queues to empty std::size_t wait_threshold{max_capacity - max_threads - 1}; // Flag to stop the writing thread once all queues are empty - bool continue_writing_{true}; + std::atomic continue_writing_{true}; /** * Constructs a concurrent writer from a writer.