I'm creating a buffer to be accessed by some threads.
struct buffer {
struct items[32];
int numItems = 0; /*will keep track of number of items in the buffer
}; and will be updated by threads when accessed.
We'll include mutex locking*/
Should I declate buffer
to be volatile or make numItems
volatile?
What I'm thinking: My understanding is that volatile should be used to prevent compiler optimizations of operations between atomic access of the data by threads. Please correct me if I'm misunderstanding this
Thanks!