General Category > General Discussion about just::thread

Thread Local Storage

(1/2) > >>

TA:
Hello Anthony,

Thread Local Storage is added as a keyword to C++ standard and it's not possible to have it in library without any special support by compiler, however it would be useful to have a portable TLS in just::thread. I couldn't find anything like that in documentation and forum, so could you please tell me if there is TLS support in just::thread?

Thanks.

Anthony Williams:
There is currently no support for TLS in just::thread. Given that the compilers supported by just::thread do have TLS support, I will consider adding it for a future release.

TA:

--- Quote from: Anthony Williams on February 03, 2011, 02:25:26 PM ---There is currently no support for TLS in just::thread. Given that the compilers supported by just::thread do have TLS support, I will consider adding it for a future release.

--- End quote ---
Thanks for your answer Anthony.

Currently I'm using compilers support for TLS, but both GCC and MSVC have the same issue, they don't allow to have objects with non-trivial constructor in thread local storage, as far as I understood from C++ Concurrency in Action examples this is allowed in C++0x, maybe something like boost::thread_specific would be more useful here?

Anthony Williams:

--- Quote from: TA on February 03, 2011, 02:36:18 PM ---Currently I'm using compilers support for TLS, but both GCC and MSVC have the same issue, they don't allow to have objects with non-trivial constructor in thread local storage, as far as I understood from C++ Concurrency in Action examples this is allowed in C++0x

--- End quote ---

Yes, in C++0x thread_local variables can be types with non-trivial constructors and destructors.


--- Quote from: TA on February 03, 2011, 02:36:18 PM ---maybe something like boost::thread_specific would be more useful here?

--- End quote ---

Maybe. boost::thread_specific_ptr is slightly different again: though each pointer is freed automatically, you have to manually allocate and construct the object for each thread.

TA:

--- Quote from: TA on February 03, 2011, 02:36:18 PM ---Maybe. boost::thread_specific_ptr is slightly different again: though each pointer is freed automatically, you have to manually allocate and construct the object for each thread.

--- End quote ---
It is, but at least it allows to have thread local objects and not to worry about freeing it up afterwards, which is simply impossible with __declspec(thread).
As far as I know boost::thread_specific is handled in special way in boost::thread calling procedure, so I can't use boost::thread_specific in std::thread, is it right?

Navigation

[0] Message Index

[#] Next page

Go to full version