1. 程式人生 > >linux 下多執行緒1

linux 下多執行緒1

舉例UNIX International 執行緒

UNIX International 執行緒的標頭檔案是<thread.h> [1]  ,僅適用於Sun Solaris作業系統。所以UNIX International執行緒也常被俗稱為Solaris執行緒。

1.建立執行緒

intthr_create(void*stack_base,size_tstack_size,void*(*start_routine)(void*),void*arg,longflags,thread_t*new_thr);

2.等待執行緒

intthr_join(thread_twait_for,thread_t*dead,void**status);

3.掛起執行緒

intthr_suspend(thread_tthr);

4.繼續執行緒

intthr_continue(thread_tthr);

5.退出執行緒

voidthr_exit(void*status);

6.返回當前執行緒的執行緒識別符號

thread_tthr_self(void);POSIX執行緒

POSIX執行緒(Pthreads)的標頭檔案是<pthread.h>,適用於類Unix作業系統。Windows作業系統並沒有對POSIX執行緒提供原生的支援庫。不過Win32的POSIX執行緒庫的一些實現也還是有的,例如pthreads-w32 [2] 

 。

1.建立執行緒

intpthread_create(pthread_t*thread,constpthread_attr_t*attr,void*(*start_routine)(void*),void*arg);

2.等待執行緒

intpthread_join(pthread_tthread,void**retval);

3.退出執行緒

voidpthread_exit(void*retval);

4.返回當前執行緒的執行緒識別符號

pthread_tpthread_self(void);

5.執行緒取消

intpthread_cancel(pthread_tthread);Win32執行緒