简体   繁体   中英

Do you have to close the thread once it has ended when using pthreads in Linux?

In WinAPI, if you create a thread and this thread is then ended, you still have to call CloseHandle() on the thread handle.

When using pthreads in Linux, do you also have to close the thread after it has ended?

The equivalent in pthreads is to call pthread_join() on the thread (this will block until the thread exits, if it hasn't already).

You also have the option to detach the thread with pthread_detach() (or create it detached using the attr argument to pthread_create() with pthread_attr_setdetachstate() ), which means the thread no longer needs to be joined.

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