Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is the default constructed thread a joinable thread?


Asked by Rosie Shepard on Dec 13, 2021 FAQ



So a default constructed thread is not joinable. A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable. true if the thread object identifies an active thread of execution, false otherwise 33.3.2.5 thread members [thread.thread.member]
And,
A joinable thread is a thread that represents a thread of execution which has not yet been joined. A thread is not joinable when it is default constructed or is moved/assigned to another thread or join() or detach() member function is called.
Keeping this in consideration, A thread object that's created by using the default constructor is not associated with any thread of execution. A thread object that's constructed by using a callable object creates a new thread of execution and calls the callable object in that thread. Thread objects can be moved but not copied.
Similarly,
Joinable thread will not release any resource even after the end of thread function, until some other thread calls pthread_join() with its ID. int pthread_join(pthread_t thread, void **retval); pthread_join() is a blocking call, it will block the calling thread until the other thread ends.
In this manner,
A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable.