Changing data in all thread specific storages.

Changing data in all thread specific storages.

I have a case where I use a map as a cache which are stored in the thread local storage using enumerable_thread_specifc. There's a method if called, has to flush out all the caches. Meaning a method call from one thread has to somehow modify all other threads' (of the application) thread local storages to flush everything out. Is this possible at all? At first glance it doesn't seem like it, but just wanted to make sure.Thank you very much.

3 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Raf Schietekat

You would have to drop out of the parallel phase first, because the threads should be able to assume that they have sole access to the data and that they don't need to release it when adding it to TLS (in the sense of release/acquire memory semantics).

Alternatives that come to mind are a shared concurrent_unordered_map, or pushing a copy of local-map changes to a concurrent_queue.

Bild des Benutzers jimdempseyatthecove

Whatnon-owner threadcould do is set a "flush" flag inside the thread local storage of the owner(s) desired to be flushed (or all threads). Any fill or empty (by owner of queue)subsequent to setting of flag results in flush first.

Doing it this way means you do not have to add a critical section, nor exit the thread pool.

The overhead to test this flag is negligable.

Jim Dempsey

www.quickthreadprogramming.com

Melden Sie sich an, um einen Kommentar zu hinterlassen.