linux中的线程函数
生活随笔
收集整理的這篇文章主要介紹了
linux中的线程函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
函數pthread_create?
作用:創建線程?
函數原型:int pthread_create(pthread_t * tidp,const pthread_attr_t*attr,void*(*start_rtn)(void),void*arg)
參數: tidp:線程id?
attr: 線程屬性(通常為空)?
start_rtn:線程要執行的函數?
arg:start_rtn的參數?
頭文件:#include <pthread.h>
函數pthread_exit?
函數功能:終止調用線程?
函數原型: void pthread_exit(void * rval_ptr)?
函數參數:Rval_ptr:線程退出返回值的指針?
頭文件:#include <pthread.h>
函數pthread_join?
函數功能:阻塞調用線程,直到指定的線程終止。?
函數原型:int pthread_join(pthread_t tid,void **rval_ptr)
函數參數:Tid :等待退出的線程id?
Rval_ptr:線程退出的返回值的指針?
頭文件:#include <pthread.h>
因為pthread的庫不是linux系統的庫,所以在進行編譯的時候要加上-lpthread即 gcc filename -lpthread
如果進程中任何一個線程中調用exit或_exit,那么整個進程都會終止。線程的正常退出方式有:?
(1) 線程從啟動例程中返回?
(2) 線程可以被另一個進程終止?
(3) 線程自己調用pthread_exit函數
作用:創建線程?
函數原型:int pthread_create(pthread_t * tidp,const pthread_attr_t*attr,void*(*start_rtn)(void),void*arg)
參數: tidp:線程id?
attr: 線程屬性(通常為空)?
start_rtn:線程要執行的函數?
arg:start_rtn的參數?
頭文件:#include <pthread.h>
函數pthread_exit?
函數功能:終止調用線程?
函數原型: void pthread_exit(void * rval_ptr)?
函數參數:Rval_ptr:線程退出返回值的指針?
頭文件:#include <pthread.h>
函數pthread_join?
函數功能:阻塞調用線程,直到指定的線程終止。?
函數原型:int pthread_join(pthread_t tid,void **rval_ptr)
函數參數:Tid :等待退出的線程id?
Rval_ptr:線程退出的返回值的指針?
頭文件:#include <pthread.h>
因為pthread的庫不是linux系統的庫,所以在進行編譯的時候要加上-lpthread即 gcc filename -lpthread
如果進程中任何一個線程中調用exit或_exit,那么整個進程都會終止。線程的正常退出方式有:?
(1) 線程從啟動例程中返回?
(2) 線程可以被另一個進程終止?
(3) 線程自己調用pthread_exit函數
總結
以上是生活随笔為你收集整理的linux中的线程函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sqlite中的命令
- 下一篇: 在linuxc中如何实现输入隐藏