class cacheObj : virtual public x::obj { // ... typedef x::ref<cacheObj> cache; typedef x::ptr<cacheObj> cacheptr; // ... cache item=cache::create(); x::weakthreadlocalObj<cacheObj> weakitem=x::makeweakthreadlocal(item);
x::makeweakthreadlocal()
constructs a weak local thread object reference.
It's
getptr
()
method is similar to a weak pointer's for
a reference-counted object, but with an
additional element that when the thread that created the weak local
thread object terminates, the pointer returned by
getptr
() becomes
null
().
Threads that create local thread object references must be created
by x::run
().
The weak local thread object references become
null
() after the object's
run
() method returns, and before the
underlying thread gets joined.
Since thread termination may involve object destruction, weak local thread references may not be instantiated in destructors of other objects, since the thread may currently be in the process of being terminated.