Is it possible to get a stream object for the main thread and `join ()` with it?

Is there a way to handle the main thread, like any other thread, using C ++ 11 (or later) tools? Specifically, I am looking for the possibility of join() with the main thread. So basically, I would like to do something like: main_thread.join() , but don't know how to get the main_thread object.

Stream constructors do not seem to offer any objects based, for example, on the identifier of the stream obtained using get_id() . The this_thread namespace this_thread offers minimal functionality, but skips, for example, join() , which I am looking for.

+5
source share
1 answer

As pointed out in the comments of @molbdnilo and @yohjb (see also What happens to a disconnected thread when main () terminates? ), C ++ 11 Semantics says that all threads terminate when the main() function terminates. Since C ++ 11 does not have the equivalent of pthread_exit() , the main thread cannot be combined because the program will end anyway.

So, to answer my question, this seems impossible, and with the final semantics of main() this would not be very useful.

+3
source

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


All Articles