afail
6th April 2009, 16:56
Hello, I am developing a Qt application which needs to lock its critical data from accesing on different instances. Thus I implement the singleton concept and I needed more low-level way to create Mutex and lock the access of critical data.
For the QT_WS_WIN scope I use:
QT_WA(
{m_hMutex=CreateMutex(0, FALSE, (TCHAR*)id().utf16());},
{m_hMutex=CreateMutexA(0, FALSE, id().toLocal8Bit().data());}
);
switch(WaitForSingleObject(m_hMutex, INFINITE))
{
case WAIT_TIMEOUT:
CloseHandle(m_hMutex);
m_hMutex = 0;
break;
}
And for QT_WS_X11 I use:
pthread_mutex_t *mutex;
pthread_mutexattr_t *attr;
// initialize them with their _init methods
and then
pthread_mutex_lock(mutex);
// critical data
pthread_mutex_unlock(mutex);
Whatsoever, the result is not as expected. For Windows the above method works well, but using the posix way, with pthread_mutex, the locking is not done as it is supposed. I think it might be related to the way the Mutex for Win32 is identified within the QT_WA macro.
Any help for finding the best replacement would be appreciated.
thanks
For the QT_WS_WIN scope I use:
QT_WA(
{m_hMutex=CreateMutex(0, FALSE, (TCHAR*)id().utf16());},
{m_hMutex=CreateMutexA(0, FALSE, id().toLocal8Bit().data());}
);
switch(WaitForSingleObject(m_hMutex, INFINITE))
{
case WAIT_TIMEOUT:
CloseHandle(m_hMutex);
m_hMutex = 0;
break;
}
And for QT_WS_X11 I use:
pthread_mutex_t *mutex;
pthread_mutexattr_t *attr;
// initialize them with their _init methods
and then
pthread_mutex_lock(mutex);
// critical data
pthread_mutex_unlock(mutex);
Whatsoever, the result is not as expected. For Windows the above method works well, but using the posix way, with pthread_mutex, the locking is not done as it is supposed. I think it might be related to the way the Mutex for Win32 is identified within the QT_WA macro.
Any help for finding the best replacement would be appreciated.
thanks