If the pointer is non-null, it's already been modified the one time it's going to get modified so it no longer needs to be protected by locking the mutex and the implied memory barriers
Last edited by Corona688; 10-05-2012 at 12:13 PM..
If the pointer is non-null, it's already been modified the one time it's going to get modified so it no longer needs to be protected by locking the mutex and the implied memory barriers
You have not addressed the issues I laid out in my last post with regards to why the above statement is irrelevant. Did you deliberately ignore them, or did I not explain them satisfactorily/did you not understand them?
I was in your position not too long ago - I did not believe the person saying what I am saying now, but I was willing to learn and be proved wrong, so I did some research.
This has the benefit that the reference can't be freed (though, as I show, the caller can jump through hoops to free it, so the private destructor is still good practice). However, I'd suspect that most people would see a reference and know that deleting it is probably bad.
Buyer beware, however, that the standard is pretty hush-hush on its thread safety. Though, most practical compilers (g++) wrap the local static member ("theSingle") with locks to insure it does not get constructed more than once. In my opinion, this is preferable to roll-your-own. However, if you must, a pthread_once_t control is probably the way to do it as here:
Which uses the same reference return to, IMO, instruct the caller that it's not theirs and they shouldn't be free'ing it.
I suppose you could also use auto pointers or something, too, but...this is good enough for me, lol.
edit: for the record, the former implementation is thread-safe in C++0x, as such, in any newer code compiled with C++0x compliant compiler, I'd recommend it to rid all the boilerplate crap and distill it right to only that code which is both sensible and required. Just one man's opinion....
Last edited by DreamWarrior; 11-06-2012 at 11:11 PM..
Medel : 9117-MMC
OS: AIX 6.1
Patch level : 6100-07-04-1216
Hacmp version : HACMP v 6.1.0.8
Oracle : 11.2.0.3 RAC
Node : 2 node
Dear, my one node server has been restarted early this morning, So, i tried to start HA and Oracle database.
after that, the follow error appears at the node... (1 Reply)
I want to create an abstract factory template which will allow me to pass in an "ID" for a subclass and return the singleton instance of that class stored in the factory. It'd be easy to adapt for "multi-ton", but for its present use this isn't necessary.
The requirements are:
- I don't want... (2 Replies)