Hi all,
I received a code that is not for multi-threaded app, now I have to modify the code to support for multi-threaded.
I have a Singleton class(MyCenterSigltonClass
) that based on instruction in:
http://en.wikipedia.org/wiki/Singleton_pattern
I made it thread-safe
Now I see inside the class that contains 10-12 members, some with getter/setter methods. Some members are declared as static and are class pointer like:
static Class_A* f_static_member_a;
static Class_B* f_static_member_b;
for these members, I defined a mutex(like mutex_a
) INSIDE the class(Class_A
) , I didn't add the mutex directly in my MyCenterSigltonClass
, the reason is they are one to one association with my MyCenterSigltonClass
, I think I have option to define mutex in the class(MyCenterSigltonClass
) or (Class_A
) for f_static_member_a
.
1) Am I right?
Also, my Singleton class(MyCenterSigltonClass
) contains some other members like
Class_C f_classC;
for these kind of member variables, should I define a mutex for each of them in MyCenterSigltonClass
to make them thread-safe? what would be a good way to handle these cases?
Appreciate for any suggestion.
-Nima