whether a method(in the shared class) needs to synchronize or not depending on the data visited by the method.For example (class A is shared by multi_threads):
1.method_1 like this does not need to synchronize.
void method_1()
{
int varable1;
varable1=a.varable1//only read varable1,not write varable1
}
void method_1()
{
int varable1;
varable1=a.varable1//only read varable1,not write varable1
}
To copy to clipboard, switch view to plain text mode
2.method_1 like this needs to synchronize.
void method_1()
{
int varable1;
caculate(varable1);
a.varable1=varable1;//write varable1
}
void method_1()
{
int varable1;
caculate(varable1);
a.varable1=varable1;//write varable1
}
To copy to clipboard, switch view to plain text mode
Am I right or not?
Bookmarks