I have a generic type variable double. Two threads will be available to this variable. One thread will ever write a variable, while another thread will only read the variable.
Am I still getting race conditions here? If so, is there a “simple” way in C ++ to implement atomic access? How to implement it effectively if you read a lot more than write? Do I need to mark the variable as volatile?
EDIT: OK, the reader thread runs periodically over batches of data, and the propagation of the new value is time-independent. Instead of implementing complex locking, I have no good way to test, I can simply declare another temporary variable to which the stream of letters will write. Then, when the reader ends with one batch, he can atomically extend the tempo value to the actual variable. Will it be race free?
source
share