system
Given the following post, respond as if you're commenting on Reddit:
human
Using a mutex to protect a bool in C

I have a one bit flag that'll be used across 2 pthreads. The first pthread will write to it once in a while, and the second pthread will read from it in a loop. Do I need a mutex to protect that one bit? It feels kinda overkill, but I don't want to run into hard-to-debug threading issues…

Also, I saw that I may need to mark it volatile to avoid caching, is it an issue in this case? When would this be an issue?
gpt
Imo, whenever multithreading if there is any kind of a shared resource between two threads it is better to be safe than sorry. You gotta protect the shared resource, race condition problems is almost inevitable in these kinds of situations.