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.
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.
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.