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 will exist (will be in scope), such as a static method, but it said I need to ensure the static is thread safe.
Part 1: What are some examples of things I could do to make it un-thread safe?
Part 2: Does this mean that if I have
static int addOne(int someNumber){
int foo = someNumber;
return foo +1;
}
and I call Class.addOne(5); and Class.addOne(6); simutaneously, Might I get 6 or 7 returned depending on who which invocation sets foo first? (i.e. a race condition)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…