c++ - Is pointer dereferencing atomic? -
lets have pointer integer.
volatile int* commonpointer = new int(); and have multiple threads dereference pointer.
int blah = *commonpointer; but, 1 thread needs change pointer's address:
int* temp = new int(); int* old = commonpointer; interlockedexchange(&commonpointer,temp); delete old; now, lets ignore fact threads may reading "old" value, , may reading "new" value, that's not issue in case.
can there scenario 1 thread starts dereference pointer, address deleted, , gets exception ?
or dereferencing atomic enough won't happen ?
nothing in c++ standard guarantees atomicity in case.
you must protect relevant code areas mutex: std::atomic not enough since provide atomic access pointer not include dereference operation.
Comments
Post a Comment