The short answer is because we are updating m_fibonacci_values inside of a mutex locked critical section. Technically speaking volatile alerts the compiler that data may change in "unexpected" ways. Because of the mutex lock, every change to m_fibonacci_values is controlled and it is impossible for one thread to update it while another is trying to read it. As an optimization (and due to the fact that booleans are updated in a single instruction inside the CPU) we are able to update m_running and m_stop_requested without using a mutex, a consequence of that is that we need to mark it as volatile.
So to sum up:
I'm sure there is a much deeper explanation of this that is outside of my scope of knowledge.
Recent comments
16 hours 24 min ago
21 hours 28 min ago
21 hours 57 min ago
1 day 14 hours ago
1 day 21 hours ago
1 week 6 days ago
3 weeks 15 hours ago
3 weeks 1 day ago
3 weeks 3 days ago
3 weeks 4 days ago