C++ 销毁锁定的互斥锁时,pthread_mutex_destroy的正确行为是什么

C++ 销毁锁定的互斥锁时,pthread_mutex_destroy的正确行为是什么,c++,linux,multithreading,pthreads,mutex,C++,Linux,Multithreading,Pthreads,Mutex,我写了以下最简单的例子: #include <iostream> #include <cstring> #include <pthread.h> #define SUCCESS 0 using namespace std; int main() { int res; pthread_mutex_t t; pthread_mutex_init(&t, NULL); res = pthread_mutex_lock(&a

我写了以下最简单的例子:

#include <iostream>
#include <cstring>
#include <pthread.h>
#define SUCCESS 0
using namespace std;

int main() {
    int res;
    pthread_mutex_t t;
    pthread_mutex_init(&t, NULL);

    res = pthread_mutex_lock(&t);

    res = pthread_mutex_destroy(&t);
    if (res != SUCCESS)
    {
        cout << "Failed to delete: " << strerror(res) << " # " << t.__data.__lock << " " << t.__data.__nusers << endl;
    }
    else
    {
        cout << "Deleted!"<< endl;
    }

    res = pthread_mutex_unlock(&t);
    cout << res << endl;
    pthread_exit(NULL);

    return 0;

}
#包括
#包括
#包括
#定义成功0
使用名称空间std;
int main(){
国际关系;
pthread_mutex_t;
pthread_mutex_init(&t,NULL);
res=pthread\u mutex\u lock(&t);
res=pthread\u mutex\u destroy(&t);
如果(res!=成功)
{
cout引用的文本:

试图破坏另一个线程引用的锁定互斥体或互斥体(例如,在
pthread\u cond\u timedwait()
pthread\u cond\u wait()
)时,会导致未定义的行为

应使用分布在“or”连词上的“results in undefined behavior”子句进行解释。换句话说:

试图销毁锁定的互斥锁会导致未定义的行为

试图破坏另一个线程引用的互斥锁(例如,在
pthread\u cond\u timedwait()
pthread\u cond\u wait()
)时,会导致未定义的行为


第二个版本很重要,因为在等待条件变量时,相关的互斥锁由等待线程释放。

如本文所述,这是一种
未定义的行为
@brokenfoot是的,但这只是在由另一个线程完成的情况下发生的吗?我试图澄清为什么有人会认为这是错误的ld很重要。只需遵守Posix规范。它是