pthread_detach手册

原文地址:http://man7.org/linux/man-pages/man3/pthread_detach.3.html

 

PTHREAD_DETACH(3)         Linux Programmer's Manual        PTHREAD_DETACH(3)

 

NAME         top

       pthread_detach - detach a thread

 

SYNOPSIS         top

       #include <pthread.h>

       int pthread_detach(pthread_t thread);

       Compile and link with -pthread.

 

DESCRIPTION         top

       The pthread_detach() function marks the thread identified by thread
       as detached.  When a detached thread terminates, its resources are
       automatically released back to the system without the need for
       another thread to join with the terminated thread.

       Attempting to detach an already detached thread results in
       unspecified behavior.

 

RETURN VALUE         top

       On success, pthread_detach() returns 0; on error, it returns an error
       number.

 

ERRORS         top

       EINVAL thread is not a joinable thread.

       ESRCH  No thread with the ID thread could be found.

 

CONFORMING TO         top

       POSIX.1-2001.

 

NOTES         top

       Once a thread has been detached, it can't be joined with
       pthread_join(3) or be made joinable again.

       A new thread can be created in a detached state using
       pthread_attr_setdetachstate(3) to set the detached attribute of the
       attr argument of pthread_create(3).

       The detached attribute merely determines the behavior of the system
       when the thread terminates; it does not prevent the thread from being
       terminated if the process terminates using exit(3) (or equivalently,
       if the main thread returns).

       Either pthread_join(3) or pthread_detach() should be called for each
       thread that an application creates, so that system resources for the
       thread can be released.  (But note that the resources of all threads
       are freed when the process terminates.)

 

EXAMPLE         top

       The following statement detaches the calling thread:

           pthread_detach(pthread_self());

 

SEE ALSO         top

       pthread_attr_setdetachstate(3), pthread_cancel(3), pthread_create(3),
       pthread_exit(3), pthread_join(3), pthreads(7)

 

COLOPHON         top

       This page is part of release 3.51 of the Linux man-pages project.  A
       description of the project, and information about reporting bugs, can
       be found at http://www.kernel.org/doc/man-pages/.

Linux                            2008-11-27                PTHREAD_DETACH(3)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值