C ++ increases id and Singleton flow

Sorry to ask so many questions this week.

I assume that the thread index returned by thread.get_id implementation specific. In the case of pthreads, is the index reused? IE, if thread 0 is started and combined, is the thread started after the words have a different identifier?

the reason I ask for this is the need to implement the Singleton template with a twist: each thread gets its own instance. I know this sounds very crazy, but threads control the hardware (cuda), which does not allow device memory sharing even at the thread level.
What is a good way to implement such a pattern?

+4
source share
1 answer

For global (singleton), where each thread gets its own instance, use local thread storage. Boost has thread_specific_ptr for this.

+5
source

Source: https://habr.com/ru/post/1307289/


All Articles