Re: Using GAllocator in a multi-threaded environment
- From: Michael Meeks <michael ximian com>
 
- To: Beni Serfaty <benis magnifire com>
 
- Cc: gnome-libs-devel gnome org
 
- Subject: Re: Using GAllocator in a multi-threaded environment
 
- Date: 28 Mar 2003 16:47:59 +0000
 
Hi Beni,
On Tue, 2003-03-11 at 14:54, Beni Serfaty wrote:
> I was happily using GQueue which seemed to be doing it's job right. When
> I applied another GQueue running from a different thread, I started
> getting sometime segmentation fault from the function _g_list_alloc - 
> (In the line 	  current_allocator->free_lists->data = list->next; )
	Well; the g_list allocator is thread safe; so this isn't likely tobe
the problem IMHO.
	You can get similar effects however by freeing the same g_list twice;
in two threads, glib can't protect you from that. So I suspect it's your
code that has some race in it. Of course - you can get the same effect
quite nicely in a single thread by g_list_freeing the same list twice so
... ;-)
> How do one work with GQueue in a multi-threaded environment: 
> (I want to use several GQueues or GLists, with different GAllocators,
> running in a multi-threaded environment). Since the current allocator is
> static in the lib code, is it even possible without locking? Is there
> some way to use a non-static allocator?
	It's thread safe; you just need to have your own locks around your own
data strutures to ensure that they are not poked by multiple threads
simultaneously.
	HTH,
		Michael.
-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot
[
Date Prev][Date Next]   [
Thread Prev][Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]