Originally Posted by
CornedBee
Seriously, though, the fact that the critical section is affected by the smart pointers constness indicates that you have one per smart pointer. Is that true? If it is, that's completely useless. Allocate a CCriticalSection next to your reference count, because like it, it must be shared among all instances that refer to the same pointer.
Once you've done that, constness will no longer be a problem.
There are two problems here:
A critical section is needed to make sure to two or more threads use the same smart pointer class at once (references via threads, anyone?). Unless, of course, I can remove that practice. Two threads should NOT use the same smart class pointer.
Code:
// Let's just assume for simplicity's sake that main calls both thread1 and thread2 in different threads.
void thread1(pp<int>& pTest)
{
int n = *pTest; // BAD!
}
void thread2(pp<int> pTest)
{
int n = *pTest; // Good, because it's not the same smart pointer
}
int main()
{
ppnew<int> p = 0;
thread1(p);
thread2(p);
}
Also, the thread affinity test should be done whether the pointer is thread-safe or not, because just because you can have more than one pointer to the same object on different threads, still doesn't mean you may use any single pointer on more than one thread at the same time. That's still dangerous.
I guess that answers my question about the above reference count, huh? I'll make some changes.