Is thread :: get_id (C ++ 11) really blocked?

I would like to check a thread calling different functions of one of my classes. I have a critical time stream, and I do not want anyone to call a function that can call new to call from this stream. However, since the two functions are publicly available, I cannot force it into the language.

My idea is to check the thread id . Assuming that I can guarantee that the call that initializes the thread id is in the correct thread, I would just need to call thread::get_id() in other calls and compare with the thread id that I saved.

The problem is that I also want to test this ID in a critical thread, but I cannot block this thread.

So my question is: is thread::get_id() free (and what could be the worst execution time)?

+4
source share
1 answer

The standard makes no guarantees as to whether thread::get_id() and std::this_thread::get_id() blocked or not, or even regarding their complexity.

I am afraid that the answer to your question depends on the implementation, depending on the specific standard library and the stream library.

+7
source

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


All Articles