I have a method as below
SomeStruct* abc;
void NullABC()
{
abc = NULL;
}
This is just example and not very interesting.
Many thread could call this method at the same time.
Do I need to lock “abc = NULL” line?
I think it is just pointer so it could be done in one shot and there isn’t really need for it but just wanted to make sure.
Thanks
It depends on the platform on which you are running. On many platforms, as long as
abcis correctly aligned, the write will be atomic.However, if your platform does not have such a guarantee, you need to synchronize access to the variable, using a lock, an atomic variable, or an interlocked operation.