Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3727

QThreadStorage misses setAutoDelete(false)

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • Not Evaluated
    • Some future release
    • 4.5.0
    • Core: Threads
    • 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sorvig Morten Sørvig
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes