Re: Glib mutex doesn't work on Windows



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/16/2010 11:47 AM, Michael T. wrote:
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

Myso,

I had this problem developing a GTK application on OpenBSD, it seems
that GMutex's are not guaranteed to be recursive or non-recursive.

I altered my code to work with GConditionals and worked fine. Perhaps,
that will work for you as well.

http://kdekorte.blogspot.com/2009/01/gnome-mplayer-094-will-work-with-bsds.html

Kevin




- -- 
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x7D0BD5D1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk0KZd8ACgkQ6w2kMH0L1dHEAgCgkUgPWaXYQ9En7Dlb6GqQwJvf
hI4AnR9IvUtixwtOD8+odP3XK4toJ+Aa
=Be88
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]