WebServer icon indicating copy to clipboard operation
WebServer copied to clipboard

对mutexlock类的一些疑问

Open freedomDR opened this issue 4 years ago • 3 comments

MutexLock的析构函数里面,销毁mutex时为什么先锁住呢?

freedomDR avatar Oct 30 '19 09:10 freedomDR

~MutexLock() { //这里加了锁之后其他线程就用不了了,相当于失效了 pthread_mutex_lock(&mutex_); //由于在linux中,互斥锁并不占用任何资源,因此这个函数除了检查锁状态以外(锁定状态则返回EBUSY)没有其他动作 pthread_mutex_destroy(&mutex_); }

请问我这样理解对吗

469826336 avatar Nov 01 '19 05:11 469826336

@469826336 对的

linyacool avatar Nov 08 '19 16:11 linyacool

"It shall be safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex results in undefined behavior."。destroy一个锁住的mutex不是有可能产生为定义的行为吗?

gykeve avatar Mar 13 '20 03:03 gykeve