I\'m working on creating a call back function for an ASP.NET cache item removal event.
The documentation says I should call a method on an object or calls I know wil
In the above example no.
Thread safety is mainly to do with stored state. You can make the above example non thread safe by doing this:
static int myInt;
static int addOne(int someNumber){
myInt = someNumber;
return myInt +1;
}
This will mean that due to context switching thread 1 might get to the call myInt = someNumber and then context switch, lets say thread 1 just set it to 5. Then imagine that thread 2 comes in and uses 6 and returns 7. Then when thread 1 wakes up again it will have 6 in myInt instead of the 5 that it was using and return 7 instead of the expected 6. :O