[英]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. 在
pthread_detach
手册页中,我读到当任何线程被分离时,然后在线程终止时它将其资源释放回系统。
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? 在
pthread_join
或在终止或处理时?
When resources are released in pthread_cancel
command. 在
pthread_cancel
命令中释放资源时。
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, pthread_join
在可连接线程上调用时返回, main
returns normally or exit
is called, main
返回正常或exit
调用, exec
is called successfully. exec
被成功调用。 It is possible, however, to exit the thread that is running main
and leave other, detached threads running. 但是,可以退出运行
main
的线程并使其他已分离的线程继续运行。 To do so, you have to call pthread_exit
in the main thread. 为此,您必须在主线程中调用
pthread_exit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.