I am using ACE threads and need each thread to have its own int member. Is that possible?
ACE calls this "Thread Specific Storage". Check this out: ACE_TSS. That's about all I know about it, sorry can't be more help.
The Wikipedia page for thread-local storage says there is a pthreads way to do this too.
Its platform specific. Windows for instance you should use __declspec( thread )
. The compiler will leverage the TLS API (TlsAlloc, TlsFree and friends), and on Win32 you shouldn always use FLS (Fiber Local Storage) instead of TLS, but the TLS API is silently redirecting you to FLS anyway on any modern Win32 version.
Yes. You can use the ACS_TSS<type>
template, which is designed for "thread specific storage" (ie: thread local variables).
For details, see the docs on ACE_TSS.
GCC directly supports TLS for some targets. You can use the GCC-specific __thread
keyword for defining thread-local variables (must be static or global).
libACE itself has thread-local stuff built in, you can check out the documentation and look at the example code.
Thread Local Storage at MSDN site is great resource Thread Local Storage template, sample template for making Thread Local Storage easier to use in C++.
There's no way to have ACE_TSS set the initial value for all threads; you can easily set the initial value just after entry in your thread function though.