Re: How to safely release a mutex?

As no body seems to know the answer, I made a test:

#include <glib.h>

int main()
	if (!g_thread_supported ()) g_thread_init (NULL);

	GMutex    *mutex = g_mutex_new();
	return 0;

It crashes on g_mutex_free without any hesitate :)

So finally the approach I use to avoid this kind of problem is using
another mutex, which does not need to be freed,
to protect the one I will free.

But I am wondering if that was needed.   Can I just use:


If thread switches just after unlock and another thread locked mutex,
the code might fail.

On Thu, Nov 13, 2008 at 4:41 PM, Peter Cai <newptcai gmail com> wrote:
> Hi all,
> Is it safe to call g_free_mutex on a locked mutex?
> If it's not, what is the correct way to do that?


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