Do I need a lock when only a single thread writes to a shared variable?
问题 I have 2 threads and a shared float global. One thread only writes to the variable while the other only reads from it, do I need to lock access to this variable? In other words: volatile float x; void reader_thread() { while (1) { // Grab mutex here? float local_x = x; // Release mutex? do_stuff_with_value(local_x); } } void writer_thread() { while (1) { float local_x = get_new_value_from_somewhere(); // Grab mutex here? x = local_x; // Release mutex? } } My main concern is that a load or