#include <QThread.h>
Inherits FX::QThreadLocalStorageBase.
QThreadLocalStorage represents data which is local to a thread only ie; when queryed, the data returned is the same across any code in the process but changes according to which thread is currently executing. Multithreading novices may not be able to think of why you would ever want to use this (given that using the stack is usually sufficient), but experts will know there are some problems unsolvable without TLS (Thread Local Storage) nor ability to retrieve a unique thread id.
Tornado implements TLS using QThreadLocalStorageBase which basically permits setting and retrieving of a void *
. QThreadLocalStorage is then implemented as a template over QThreadLocalStorageBase to make it more C++ friendly. To use QThreadLocalStorage, pass the pointer to the type of the data you wish to make thread-local:
class MyLocalData { int foo; }; static QThreadLocalStorage<MyLocalDataBase *> thrlocaldata; ... // NOTE: Very very important you ALWAYS initialise on first use with TLS (think about it!) if(!thrlocaldata) thrlocaldata=new MyLocalData; ... if(thrlocaldata->foo>8) ...
Public Member Functions | |
QThreadLocalStorage (type *initval=0) | |
type * | operator= (type *a) |
operator type * () const | |
type * | operator-> () const |
FX::QThreadLocalStorage< type >::QThreadLocalStorage | ( | type * | initval = 0 |
) | [inline] |
Constructs the TLS, optionally storing an initial value (for the current thread) immediately.
type* FX::QThreadLocalStorage< type >::operator= | ( | type * | a | ) | [inline] |
Operator overload allowing the pointer to the type represented by this object to be set
FX::QThreadLocalStorage< type >::operator type * | ( | ) | const [inline] |
Operator overload permitting automatic retrieval of the pointer to the type represented by this object