The problem you'll have is that without some sort of locking or memory barrier it is possible (for example) that the gui thread might set the bool
to true but the thread won't actually see this due to compiler optimizations or optimizations at the CPU level.
What you need to do is write to the bool
in such a way that the current state is loaded from memory, and the new state is correctly written back so that all threads will see the change. One way to do this is with a mutex, as you've identified. Others ways are to use memory barriers to ensure that you're accessing a correct view of memory. Most languages or OSs usually have some sort of API for manipulating memory up to the size of a word in an atomic fashion. For example, on Windows there's the InterlockedCompareExchange function.
However, in 95% of cases just wrapping the read/write in a mutex is good enough from a performance standpoint and is easy to reason about in terms of multithreaded correctness.