I have following code
int i; //gobal var
Thread1:
{
...
i=some value;
}
Thread2:
{
if (i==2) dosomething();
else dosomethingelse();
i = 4;
}
I want to write it to be thread safe without using synchronization objects and in C++ standard way.
my questions is how to have a variable to read/write access by different threads with out using synchronization? my requirement is have a bool variable which can have true or false.
Is volatile variable is atomic.
Please note that i am not supposed to use any libraires like TBB which has atomic variable.
Reason for asking this question we don't want to take and release semphore every time we access the variable in thread, as this variable changed not very often.