是否有 "single mutex deadlock" 的术语(非递归互斥的死锁类型情况)?
Is there a term for a "single mutex deadlock" (deadlock-type situation with non-recursive mutex)?
由于多次调用获取非递归互斥体,以下代码挂起:
#include <pthread.h>
class Lock
{
public:
Lock( pthread_mutex_t& mutex )
: mutex_( mutex )
{
pthread_mutex_lock( &mutex_ );
}
~Lock()
{
pthread_mutex_unlock( &mutex_ );
}
private:
pthread_mutex_t& mutex_;
};
class Foo
{
public:
Foo()
{
pthread_mutex_init( &mutex_, NULL );
}
~Foo()
{
pthread_mutex_destroy( &mutex_ );
}
void hang()
{
Lock l( mutex_ );
subFunc();
}
void subFunc()
{
Lock l( mutex_ );
}
private:
pthread_mutex_t mutex_;
};
int main()
{
Foo f;
f.hang();
}
有没有形容这种情况的词或短语?我不确定,但我认为这不能恰当地称为死锁:我的理解是死锁本身是指因无法通过地有序获取 multiple[=19= 而导致的僵局] 共享资源。
我一直称其为 "single mutex deadlock",但我想知道是否有更合适的 term/phrase。
"self deadlock" 或 "recursive deadlock".
The Wikipedia article on reentrant mutexes cites Pattern-Oriented Software Architecture, 里面用到了 "self-deadlock." 这个词我觉得挺有道理的!
...mutexes come in two basic flavors: recursive and non-recursive. A recursive mutex allows re-entrant locking, in which a thread that has already locked a mutex can lock it again and progress. Non-recursive mutexes, in contrast, cannot: a second lock in the same thread results in self-deadlock. Non-recursive mutexes can potentially be much faster to lock and unlock than recursive mutexes, but the risk of self-deadlock means that care must be taken when an object calls any methods on itself, either directly or via a callback, because double-locking will cause the thread to hang.
(强调)
跨多种技术的各种搜索结果证实了该术语的使用。
根据 manual 这是 未定义的行为 从同一线程锁定默认初始化的 mutex
两次:
If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in undefined behavior.
由于多次调用获取非递归互斥体,以下代码挂起:
#include <pthread.h>
class Lock
{
public:
Lock( pthread_mutex_t& mutex )
: mutex_( mutex )
{
pthread_mutex_lock( &mutex_ );
}
~Lock()
{
pthread_mutex_unlock( &mutex_ );
}
private:
pthread_mutex_t& mutex_;
};
class Foo
{
public:
Foo()
{
pthread_mutex_init( &mutex_, NULL );
}
~Foo()
{
pthread_mutex_destroy( &mutex_ );
}
void hang()
{
Lock l( mutex_ );
subFunc();
}
void subFunc()
{
Lock l( mutex_ );
}
private:
pthread_mutex_t mutex_;
};
int main()
{
Foo f;
f.hang();
}
有没有形容这种情况的词或短语?我不确定,但我认为这不能恰当地称为死锁:我的理解是死锁本身是指因无法通过地有序获取 multiple[=19= 而导致的僵局] 共享资源。
我一直称其为 "single mutex deadlock",但我想知道是否有更合适的 term/phrase。
"self deadlock" 或 "recursive deadlock".
The Wikipedia article on reentrant mutexes cites Pattern-Oriented Software Architecture, 里面用到了 "self-deadlock." 这个词我觉得挺有道理的!
...mutexes come in two basic flavors: recursive and non-recursive. A recursive mutex allows re-entrant locking, in which a thread that has already locked a mutex can lock it again and progress. Non-recursive mutexes, in contrast, cannot: a second lock in the same thread results in self-deadlock. Non-recursive mutexes can potentially be much faster to lock and unlock than recursive mutexes, but the risk of self-deadlock means that care must be taken when an object calls any methods on itself, either directly or via a callback, because double-locking will cause the thread to hang.
(强调)
跨多种技术的各种搜索结果证实了该术语的使用。
根据 manual 这是 未定义的行为 从同一线程锁定默认初始化的 mutex
两次:
If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in undefined behavior.