From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-01 11:44:44
> > I think that on Win32 a thread::ref can contain only a HANDLE (and
> a DWORD
> > if you insist on being able to compare thread::refs for equality -
> you can't
> > compare HANDLEs.)
> Yes, but this requires calls to DuplicateHandle which *do the exact
> same thing that a ref-counted implementation would do*. The overhead
> is going to be identical.
We'll have to measure to be sure, since, as I said, Windows might use
problem-specific techniques that shared_ptr<thread>(new thread) can't match.
[Or it might not. Only the profiler can tell for sure.]
But the real point is that, in this example, thread::ref has no overhead
compared to a noncopyable thread; the noncopyable thread will store the
exact same data, and execute exactly the same actions on
Therefore, a thread::ref is identical to a thread - ignoring the copy
constructor and the assignment operator. You can even reference count it
yourself, if you like.
> It may not be possible if extra data must be maintained above and
> beyond what a HANDLE maintains.
True. So we can't reach a conclusion on this point if we don't know what the
rest of the design will demand.
> With a noncopyable design and new/delete you can employ explicit
> management which will be faster than ref-counting.
Ah, I see, you're referring to using raw pointers and manual deallocation.
> I see no way that a claim can be made that the ref-counting design
> shall incur no overhead in comparison to a noncopyable design, while
> the reverse claim can be made for at least some usage, and for others
> we can make a claim of less overhead.
I see that you're objecting to my "no overhead" claim. Let me rephrase it
A thread::ref - based design does not inherently impose overhead. A typical
implementation will have no measurable overhead over a noncopyable thread
object, if a thread::ref is never copied.
I think that the ease of use justifies the small price.
Either way, the decision is yours. I'll shut up now.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk