[cpp-threads] Asynchronous Function Proposal
Peter Dimov
pdimov at mmltd.net
Tue Jun 9 07:58:39 BST 2009
Boehm, Hans:
> I think it's more than "value semantics", right?
>
> Assume I have functions f() and g() in libraries L1 and L2 respectively.
> Let's say g() caches its argument in a thread local, and f(g, x, y, z) may
> sometimes invoke g(y). In order to be able to determine whether I can
> safely invoke f(g, x, y, z) from an async that may recycle threads, I
> think I need to know all of the above, at least if y's destruction relies
> on something of limited lifetime.
If y's destruction relies on something of limited lifetime, Y does not have
value semantics. A type that obeys value semantics can be copied, and its
copy is completely independent of the original, although equivalent to it in
every way except identity.
Extending the lifetime of a function argument after the function returns
relies on this property, and this is an issue that is conceptually
orthogonal to thread locals.
void f( T & t1, T t2 )
{
t1 = t2;
}
This extends the lifetime of t2 to that of the object t1 refers to.
Yes, thread locals and global variables do expose the issue, but it exists
independently of them. Types whose lifetime ends abruptly before their
destructor runs are a time bomb, pure and simple. They will never be safe to
use, no matter how many language features you remove.
More information about the cpp-threads
mailing list