This is a threading question where I basically started making a library thread-safe. My use-case is as follows –
struct <>
{
int thread_specific_value;
}
1) Spin 5 threads for example.
2) Each thread does operation and store thread_specific_value in the above data structure for example. This is dynamically allocated at the initialization of each thread and added to QThreadStorage.
3) Once all threads return to main thread, I like to access the errno values of all threads and do some processing. Before I delete the thread from the main thread, can I get the information of its storage data and store in main thread’s specific storage.
In nutshell, how can I iterate through QThreadStorage of all the thread specific stored data and do some processing from main thread?
Data stored in QThreadStorage is accessible only from the thread that put it there. Period. If you want to access the same data from other threads, you must store it additionally elsewhere. In particular, the thread-specific value is destroyed on thread exit; if you want to keep the value, save it somewhere before the thread exits.
In short, don’t try to use QThreadStorage for inter-thread communication. That’s not what it’s there for.