Difference between revisions of "Pthread"
From Teknologisk videncenter
m |
m (→Releasing ressources used by a pthread) |
||
Line 1: | Line 1: | ||
− | =Releasing | + | =Releasing resources used by a pthread= |
− | To release the | + | To release the resources - memory for stack and householding - it is necessary to call either [https://www.man7.org/linux/man-pages/man3/pthread_detach.3.html pthread_detach] or [https://www.man7.org/linux/man-pages/man3/pthread_join.3.html pthread_join]. The resources are not released when the pthread exits without one of these calls. |
+ | *[https://www.man7.org/linux/man-pages/man3/pthread_join.3.html pthread_join] is called by the process or another thread. | ||
+ | *[https://www.man7.org/linux/man-pages/man3/pthread_detach.3.html pthread_detach] is typically called by the thread itself to release the resources when the thread terminates | ||
+ | |||
=Links= | =Links= | ||
*[https://computing.llnl.gov/tutorials/pthreads/ Tutorial on pthreads from Lawrence Livermore National Laboratory] (Good) | *[https://computing.llnl.gov/tutorials/pthreads/ Tutorial on pthreads from Lawrence Livermore National Laboratory] (Good) | ||
*[https://www.yangyang.cloud/blog/2018/11/09/worker-pool-with-eventfd/ Pthread example: Worker poll with eventfd] | *[https://www.yangyang.cloud/blog/2018/11/09/worker-pool-with-eventfd/ Pthread example: Worker poll with eventfd] | ||
[[Category:C]][[Category:Linux]] | [[Category:C]][[Category:Linux]] |
Revision as of 06:33, 3 December 2020
Releasing resources used by a pthread
To release the resources - memory for stack and householding - it is necessary to call either pthread_detach or pthread_join. The resources are not released when the pthread exits without one of these calls.
- pthread_join is called by the process or another thread.
- pthread_detach is typically called by the thread itself to release the resources when the thread terminates