A class is declared as:
class Test
{
public:
void StringMethod(char a[]) {...}
void IntMethod(int b) {...}
};
and two instances of the Test have been created, OTest1, OTest2.
In Thread A, it calls StringMethod() and IntMethod():
char aString[] = "dsfgsd";
int nInt = 123;
OTest1.StringMethod(aString);
OTest1.IntMethod(nInt);
In Thread B, it calls StringMethod() and IntMethod() also:
char aString[] = "hjkhgjk";
int nInt = 5678;
OTest2.StringMethod(aString);
OTest2.IntMethod(nInt);
My questions are:
Should the calls to StringMethod() and IntMethod() be synchronized?
Now, put the thread function inside the class declaration and keep the rest
the same, OTest1 and OTest2, etc. Thread A and B now run in the scope of
class Test.
If aString or nInt are local variables inside the thread function,
class Test
{
public:
void StringMethod(char a[]) {...}
void IntMethod(int b) {...}
static unsigned __stdcall thread_cal(void * ar)
{
char aString[] = "hjkhgjk";
int nInt = 5678;
StringMethod(aString);
IntMethod(nInt);
}
};
should the calls (StringMethod/IntMethod) be synchronized?
If aString or nInt become member variables inside of class Test, and again
two Test objects, OTest1 and OTest2, are created:
class Test
{
public:
static unsigned __stdcall thread_cal(void * ar)
{
StringMethod(aString);
IntMethod(nInt);
}
private:
char *aString;
int nInt;
void StringMethod(char a[]) {...}
void IntMethod(int b) {...}
};
should the calls (StringMethod/IntMethod) be synchronized?