k***@kaxy.com
2007-06-05 18:13:49 UTC
I have written a simple thread safe class in C++ that implements the
Singleton design pattern. Since the Singleton is supposed to be
thread-safe, it's "business logic data structure" has mutex
protection. However, I am not protecting the singleton instance
static attribute for the following reasons:
1) In C++ memory for static attributes of classes is allocated prior
to the execution of main() [or so I believe]. So when this attribute
is assigned a value, there is no inter-thread contention to deal with
2) The singleton instance static attribute is written to only once
during the lifetime of a process
One of my colleagues feels that access to the singleton instance
static attribute should also have mutex protection.
Any insight will be appreciated.
Thanks,
Bhat
Singleton design pattern. Since the Singleton is supposed to be
thread-safe, it's "business logic data structure" has mutex
protection. However, I am not protecting the singleton instance
static attribute for the following reasons:
1) In C++ memory for static attributes of classes is allocated prior
to the execution of main() [or so I believe]. So when this attribute
is assigned a value, there is no inter-thread contention to deal with
2) The singleton instance static attribute is written to only once
during the lifetime of a process
One of my colleagues feels that access to the singleton instance
static attribute should also have mutex protection.
Any insight will be appreciated.
Thanks,
Bhat