[Development] QThreadStorage and C++11
Olivier Goffart
olivier at woboq.com
Thu Mar 31 10:39:20 CEST 2016
Am Mittwoch, 30. März 2016, 22:23:35 CEST schrieb Konstantin Tokarev:
> Hello,
>
> Are there any plans to reimplement QThreadStorage via thread_local for
> compilers which support it?
QThreadStorage is already implemented with __thread which is a bit like
thread_local before it existed.
https://code.woboq.org/qt5/qtbase/src/corelib/thread/qthread_unix.cpp.html#_ZL17currentThreadData
But it's not possible to make each instance of QThreadStorage a thread_local,
because QThreadStorage is creating an instance and you can't have thread_local
per instance of QThreadStorage.
The best we could do is a macro: something like this
// if the compiler don't have thread_local
#define Q_THREAD_LOCAL(TYPE, XX) QThreadStorage<TYPE> XX
// else
#define Q_THREAD_LOCAL(TYPE, XX) thread_local QFakeThreadStorage<TYPE> XX
(where QFakeThreadStorage is just a class that contains an instance with
the same API as QThreadStorage)
--
Olivier
Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
More information about the Development
mailing list