If I have one global variable in a java class and I am running many threads, then threads may compete for that variable resulting in unconcurrent values. As far as I know semaphores and mutex can be used for such case, but are there any other approaches that can be used? (I am talking from the design aspect)
Code example:
public class Foo {
int var1;
void func1 () {
var1 = 5;
}
}
Aucun commentaire:
Enregistrer un commentaire