Kohinoor24
September 17th, 2002, 11:01 AM
I have a multithreaded application running under Linux.
When Iam Debugging I have another problem ,Iam getting a Deadlock
I have implemented the LinuxMutex class as follows:
LinMutex::LinMutex()
{
pthread_mutex_init(&m_hMutex,(pthread_mutexattr_t*)NULL);
}
void LinMutex::AcquireLock()
{
pthread_mutex_lock(&m_hMutex);
}
void LinMutex::ReleaseLock()
{
pthread_mutex_unlock(&m_hMutex);
}
LinMutex::~LinMutex()
{
pthread_mutex_destroy(&m_hMutex);
}
Is it alright.I heard from a colleuge,that If a thread which already owns a Mutex,Try to access,it again there will be a deadlock under Linux.
In windows,I have implemented the lock() as follows to remove the DeadLock as said in Msdn:
// from Msdn
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the mutex satisfied a wait.
void WinMutex::AcquireLock()
{
while (WaitForSingleObject(m_hMutex,1000L)!= WAIT_OBJECT_0);
}
What should I do to remove the Deadlock.What should be done in The AcquireLock() of LinMutex.
Could anyone help me on this regard.....
When Iam Debugging I have another problem ,Iam getting a Deadlock
I have implemented the LinuxMutex class as follows:
LinMutex::LinMutex()
{
pthread_mutex_init(&m_hMutex,(pthread_mutexattr_t*)NULL);
}
void LinMutex::AcquireLock()
{
pthread_mutex_lock(&m_hMutex);
}
void LinMutex::ReleaseLock()
{
pthread_mutex_unlock(&m_hMutex);
}
LinMutex::~LinMutex()
{
pthread_mutex_destroy(&m_hMutex);
}
Is it alright.I heard from a colleuge,that If a thread which already owns a Mutex,Try to access,it again there will be a deadlock under Linux.
In windows,I have implemented the lock() as follows to remove the DeadLock as said in Msdn:
// from Msdn
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the mutex satisfied a wait.
void WinMutex::AcquireLock()
{
while (WaitForSingleObject(m_hMutex,1000L)!= WAIT_OBJECT_0);
}
What should I do to remove the Deadlock.What should be done in The AcquireLock() of LinMutex.
Could anyone help me on this regard.....