sounds like homework to me...
You want to lock the variable so that no other process can change the value whilst your script runs, otherwise any logical processing you do may be affected by the change in value leading to unexpected results which woudl be really difficult to debug.
Also, I am not sure that you can change the value of a variable within the script unless you have it locked for write.