是否可以在 Windows 中对互斥体进行静态初始化? [英] Is it possible to do static initialization of mutexes in Windows?
问题描述
pthread 支持使用 PTHREAD_MUTEX_INITIALIZER 静态初始化 pthread_mutex_t.
pthread supports static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER.
是否可以使用 Windows 互斥锁实现类似的互斥锁初始化静态机制?
Is it possible to achieve a similar static mechanism for mutex initialization using Windows mutex?
推荐答案
不,因为 Windows 互斥是句柄,它们必须用 CreateMutex()
.
No, since Windows mutex are handles, they must be initialized with CreateMutex()
.
注意,使用 PTHREAD_MUTEX_INITIALIZER
静态初始化 pthread_mutex_t 并不是真正的初始化,它会在第一次调用 pthread_mutex_lock()
或 pthread_mutex_trylock 时在内部完成()
Note that the static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER
is not a real init, it will be done internally at the first call to pthread_mutex_lock()
or pthread_mutex_trylock()
这篇关于是否可以在 Windows 中对互斥体进行静态初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!