linux和windows多线程同步API的区别

时间:2021-08-03 17:38:33

对象

操作

Linux

Windows

线程

创建

Pthread_create

CreateThread/Afxbeginthread

退出

Pthread_exit

ThreadExit

等待

Pthread_join

WaitForSingleObject

互斥锁

创建

Pthread_mutex_init

CreateMutex

销毁

Pthread_mutex_destroy

CloseHandle

加锁

Pthread_mutex_lock

WaitForSingleObject

解锁

Pthread_mutex_unlock

ReleaseMutex

条件变量

创建

pthread_cond_init

CreateEvent

销毁

Pthread_cond_destroy

CloseHandle

触发

pthread_cond_signal

SetEvent

广播

Pthread_cond_broadcast

SetEvent/ResetEvent

等待

Pthread_cond_wait

SingleObjectAndWait

Pthread_cond_timedwait

 

 

 

 

Linux专有的

Pthread_cleanup_push:

Pthread_cleanup_pop:

这两个函数用来保护当程序出现异常时,清除资源等。

Windows专有

Semaphore