=?us-ascii?Q?Glib=20mutex=20doesn=27t=20work=20on=20Windows?=
- From: Michael T. <myso77 seznam cz>
- To: gtk-app-devel-list gnome org
- Subject: Glib mutex doesn't work on Windows
- Date: Thu, 16 Dec 2010 19:47:27 +0100 (CET)
Hi,
I'm using glib mutexes on Windows and I think they don't work.
I tried to use WIN API mutexes instead and they did work.
Short sample program:
I initialize the WIN API mutex, then create two threads using WIN API with this simple code:
DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
int i = 0;
for(i=0; i<30; i++)
{
WaitForSingleObject( Mut, INFINITE);
printf("Jozko jolko %d, thread %d\n", i, GetCurrentThreadId()) ;
ReleaseMutex(Mut);
}
return 0;
}
Without the mutexes the output is messy, because the console is a critical section, and unsynchronized
threads create mess. With mutexes applied the output is nice and clean.
When I try the Glib mutex with the same code, it doesn't work and output remains messy.
The mutex initialization looks like this:
GStaticMutex dataMutex = G_STATIC_MUTEX_INIT;
The function:
DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
int i = 0;
for(i=0; i<30; i++)
{
g_static_mutex_lock(&dataMutex);
printf("Jozko jolko %d, thread %d\n", i, GetCurrentThreadId()) ;
g_static_mutex_unlock(&dataMutex);
}
return 0;
}
I used the GStaticMutex according the example code here:
http://library.gnome.org/devel/glib/2.17/glib-Threads.html#g-static-mutex-lock
There's no problem with compiling, I also don't get any error during execution. I am using MinGW compiler to
create the binaries.
Why does it not work?
Thanks
myso
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]