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 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

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.

The overhead to test this flag is negligable.

Jim Dempsey

www.quickthreadprogramming.com

登陆并发表评论。