简体   繁体   中英

When thread release its resources

In man page of pthread_detach i read that when any thread is detached then at a time of thread termination it release its resources back to system.

What are thread resources?Is that it is a part of memory used by that thread, if it is so then that memory is a part of a process address space. I am trying to understand this but i dint got it.

And what about the joinable thread, when does thread release its resources? at a time of pthread_join or at a time of termination or process?

When resources are released in pthread_cancel command.

Every thread consumes some amount of bookkeeping resources in the operating system, as well as its own execution stack in userspace memory. Those resources are freed when the thread is destroyed, which can occur under several conditions, such as:

  • pthread_join returns when called on a joinable thread,
  • a detached thread's entry function returns,
  • main returns normally or exit is called,
  • the process is terminated due to receiving an unhandled signal,
  • exec is called successfully.

It is possible, however, to exit the thread that is running main and leave other, detached threads running. To do so, you have to call pthread_exit in the main thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM