Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Changing data in all thread specific storages.

dulantha_f
Beginner
286 Views
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.
0 Kudos
2 Replies
RafSchietekat
Valued Contributor III
286 Views
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.
0 Kudos
jimdempseyatthecove
Honored Contributor III
286 Views
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
0 Kudos
Reply