How can I get an object std::threadrepresenting the current (already running thread).
std::thread
I know what I can do std::this_thread::get_id(). However, this will give me an object std::thread:id.
std::this_thread::get_id()
std::thread:id
My main goal is to allow some other threads to join the current one. However, the problem is that the current one was not started by creating std :: thread, so I could not save it in advance.
You cannot get an object std::threadthat refers to a thread that was not created by the constructor std::thread. Either use the C ++ thread library, or don't use it at all. If the current thread was created pthread_create, for example, it will need to be combined with pthread_join.
pthread_create
pthread_join
std::threadnot copied. The ability to arbitrarily receive a stream without receiving resources from the initial creation will disrupt the flow.
Any reference to the stream must be or was transferred from the object to which the constructor was called.
, std::thread " ", () " "
" " , , main(), std::thread() (, , ). .
" " , std::thread.
" " , , . , "join()" , join() , API (, POSIX) .
In any case, it seems that for good reason you cannot do what you wanted.
Source: https://habr.com/ru/post/1669888/More articles:Lambert conformal projection in d3 - javascriptAccounting for white space in a capture group - javaReactjs + D3 v4 projection issue - reactjsHow to fix a stream error "TouchHistoryMath. Duplicate module provider" - reactjsКак протестировать Angular 2 заголовка, отправленных службой с помощью модуля Http? - unit-testingHow to determine the number of augmented images in Keras? - generatorИтерация через массив строк, извлеченных из MongoDB - mongodbWhy parseInt fails to validate arrays correctly in Javascript? - javascriptRequest request generated for EntitySet is invalid - entity-frameworkBig gif from a third-party site not showing up on README.md on github? - githubAll Articles