Case Study: The Thread Pool Passed 64/64 Tasks. ThreadSanitizer Found the Race in the Destructor
Case Study: The Thread Pool Passed 64/64 Tasks. ThreadSanitizer Found the Race in the Destructor The thread pool passed every functional test on the first run: 64 tasks enqueued, 64 results returned, clean exit. ThreadSanitizer found a data race in the destructor on the same run. The writer was a free model; the reviewer was a sanitizer on a free server; the bug was a missing lock scope that no…
The thread pool successfully completed all 64 tasks during its initial run, returning the expected results and exiting cleanly. However, despite passing all functional tests, ThreadSanitizer identified a data race within the destructor on the same run. The author, using a free model for code generation and the same pipeline for reviewing their own code, discovered a missing lock scope within the destructor that functional tests had not detected.
The small batch hashing tool, designed to compute SHA-256 for every file in a directory, utilized an embarrassingly parallel worker pool. The pool was generated using MonkeyCode's free model endpoint and executed with MonkeyCode's free server for sanitizers. The author's goal was to ensure that every task enqueued before destruction either runs or is dropped safely, without crashes or use-after-free issues.
Destruction must not race with a worker still executing, and attempting to enqueue tasks after destruction should throw an error instead of corrupting the queue.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.