开发者

Is there a way to use thread local variables when using ACE?

开发者_如何学JAVAI 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜