I have 2 functions.
void fn1() and void fn2(). Both the functions are using the same data say int i; Both the functions are executed simultaneously by 2 different processes. Then how should the variable i be protected such that 1 function should not be allowed to change i until the other changes something like locking the variable i and then unlocking it.
I need some simple example of how locking and unlocking of i is done(not using built API's of semaphore etc)