Should I disconnect or join pthread?

The pthread_detach() documentation says:

The pthread_detach() function should indicate the implementation that the storage for the thread thread can be restored when this thread terminates.

What is the consequence, if I create a connected thread and do not disconnect it or join it? Resources of this thread will not be fixed?

+4
source share
3 answers

Have you answered your question? A stream requires certain resources in the system. They will remain until no thread is connected, or it is disconnected, and it stops. (Until you disconnect the thread, the system should assume that you will join it sometime in the future and cannot free up resources.)

+3
source

That is right; you will be a resource leak if you do not attach and disconnect the stream.

Each thread will allocate some memory for its stack and probably some control structures, and this memory will not be freed. On some operating systems, there is a limit on the number of threads that you can run, and you can end up with a state in which you can no longer run.

+2
source

Just a resource associated with the thread that is supported for the connection operation (for example, a status code and a little more).

"Separately" means that I am not going to name the connection in this thread, so clear the data that depends on the thread when the thread executes (this would be done by calling the connection).

+2
source

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


All Articles