tags:

views:

71

answers:

2

Hi all,

If we want to use thread specific data in a multithreaded application, how to access those data from another collector thread periodically? Is it possible?

Regards Ram

+1  A: 

Yes, all the threads in the process (application) share the same memory. Just give the address of the data to the collector thread. Be careful with concurrent access: reading some parts of the memory while it's being updated. You might need to protect some memory zones with mutex.

philippe
Thanks! So do you mean that, we need to put addresses allocated in all threads for my data in a common list or something, where the collector thread can go and refer, access and fetch data? In a synchrnoized way?
Aviator
Yes, or you can pass the address[es] to your collector thread when you create it.
philippe
Thanks phillipe!
Aviator
A: 

Under certain systems it is possible to create variables in so-called thread-local storage. Gcc manual explains how you can achieve it and provides the link to Drepper's article, that explains technical details. This is a C standard extension, so under your system there should be a different mechanism.

Pavel Shved
It seems to be very infromative. THanks a lot. I will have a look at it.
Aviator