Previous | Next --- Slide 43 of 75
Back to Lecture Thumbnails
evs

When it comes to coding in C++. Suppose you had a multithreaded program and performed int i = shared_variable++; someFunction(shared_variable); Is there any guarantees that shared_variable will be incremented before you grab the shared variable?

leave

@evs if these codes are in the same thread, then yes, shared_variable will be incremented before being passed to the function, but other threads might also update shared_variable unexpectedly

jiaju

Are these relaxations some of the optimizations implemented in compilers (say when we add -O0 or -O3) or are they decisions made by hardware designers?

victor

I am confused why the read is allowed to start before the write is finished... wouldn't the value not be guaranteed to be changed until the end of the write step? And wouldn't that lead to the read step reading an unpredictable value?

minglotus

why the read is allowed to start before the write is finished

I think it's because the read of X is allowed before the write of Y; in other words, read of X is not allowed before the write of X if readX is after writeX in the original program order.

Please log in to leave a comment.