This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with recursive mutex : pthread_mutex_unlock() returns EPERM code


Hello All!

I have problem with recursive mutex.
pthread_mutex_unlock()
 returns 1 EPERM code. I do not understan what I'm
doing wrong,
can you help me, please?

I'm using pthread-win32 snapshot 2004-11-22 pre-build
 library. The library taken from here:
http://sources.redhat.com/pthreads-win32/


I managed to reproduce problem in simple test
application.
 Abort happens here after some time of work of this
program:

#include <pthread.h>
#include <windows.h>

class MutexWrapper
{
public:
	// mutex initialization
	MutexWrapper()
		: m_reg_mutex(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
	{
	}

	// mutex freeing
	~MutexWrapper()
	{
		pthread_mutex_destroy(&m_reg_mutex);
	}

	// locks the mutex
	void Lock()
	{
		pthread_mutex_lock(&m_reg_mutex);
	}

	void UnLock()
	{
		const int retCode =
pthread_mutex_unlock(&m_reg_mutex);
		if(retCode)
                        // abort happens here after
some time of work of program
			abort();
	}

private:
	pthread_mutex_t m_reg_mutex;    // mutex object
member
};

unsigned long WINAPI threadFunc(void *mux)
{
	while(true)
	{
		reinterpret_cast<MutexWrapper *>(mux)->Lock();
		reinterpret_cast<MutexWrapper *>(mux)->UnLock();
	}
	return 0;
}

int main(int argc, char* argv[])
{
	MutexWrapper mux;
	CreateThread(0, 0, threadFunc, &mux, 0, 0);

	while(true)
	{
		mux.Lock();
		mux.UnLock();
	}

	return 0;
}


================
the project settings of test application:
 linker options: pthreadVC1.lib /nologo
/subsystem:console /incremental:no
/pdb:"Release/CsuByteArrayTest.pdb" /machine:I386
 compiler options: /nologo /MD /W3 /GX /O2 /D "WIN32"
/D "NDEBUG" /D "_CONSOLE"
/D "_MBCS" /Fo"Release/" /Fd"Release/" /FD /c

problem reproduces with MSVC 6.0 sp5 compiler

problem reproduces on WinXP sp2, and on Windows 2000
sp4

Best Regards,
Voronkov Konstantin


		
__________________________________ 
Do you Yahoo!? 
All your favorites on one personal page ? Try My Yahoo!
http://my.yahoo.com 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]