Details
-
Suggestion
-
Resolution: Out of scope
-
Not Evaluated
-
4.5.0
-
None
Description
Sometimes it would be useful to have a way to tell QThreadStorage<T> not to autodelete T instances.
Case 1: when T* can be deleted independently; then one wants to let T's destructor tell the QThreadStorage "I have been deleted, remove me", but setLocalData(0) calls delete on T again -> crash.
One can work around it by calling a virtual destroy method that calls setLocalData(0) on the thread storage, but the problem is back again:
Case 2: a per-thread object A can delete other per-thread objects B
(QThreadStorage<A> and n*QThreadStorage<B>, where A can at various times delete all instances of B, which are however separated for API reasons, B::self() being per-thread)
Depending on the order in which the QThreadStorage's are cleaned up when the thread exits, either case 1 happens (A calls B->destroy, ok) or the thread storage for the B objects is cleaned up before A and then when A calls B->destroy B is already deleted.
So having QThreadStorage::setAutoDelete(false) would be nice. For now, one can work around it by using a wrapper that contains a T* and doesn't delete it.