简体   繁体   中英

Thread-specific data

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM