Re: calls of g_slice_new in different threads return the same address?

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

 



Hello.

Dne 11.03.2014 (tor) ob 19:15 +0800 je sunxiaobin napisal(a):
>  Hi,
>  I am using  g_slice_new to alloc some memory in my work, and it seems that sometimes same 
>  address would be returned if g_slice_new in different threads are called at the same time,  I'm  
>  wondering if anyone has ever encountered this problem? or it's already a known bug?  because
>  i am using the glib2-2.12.3, it's really a bit old now.
> 
>  i write a test program to create three threads to keep alloc and free mems using g_slice_new and 
>  g_slice_free respectively,  i will put the allocated mem in a hash table, so everytime after calls to 
>  g_slice_new, i check if it's in the hash table , and it turns out that it does happen. and if i set    G_SLICE=always_malloc  before i run the test program, there will be no problem.  any advice will
>  be appreciated.
> 
>  Attached is my test program, i copy some codes from ghash.c so that it can be compiled only with 
>  gcc -o gslice_test gslice_test.c -lglib-2.0 -I/usr/include/glib-2.0/ -I/usr/lib64/glib-2.0/include/ -pthread -g
> 
>  Here is my enviroment:
>  os:  Linux 183 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
> 		(old enough too)
>  glib version: 
>   glib2-debuginfo-2.12.3-2.el5.centos
>   glib2-2.12.3-2.fc6
>   glib2-2.12.3-2.fc6
>   glib2-devel-2.12.3-2.fc6
>   glib2-devel-2.12.3-2.fc6
> 
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list@xxxxxxxxx
> https://mail.gnome.org/mailman/listinfo/gtk-list


If I'm not mistaken, older releases of GLib are not thread-safe by
default: you need to call g_thread_init(). Does adding this call makes
any difference?

Cheers,
Tadej

-- 
Tadej Borovšak
tadej.borovsak@xxxxxxxxx
tadeboro@xxxxxxxxx
blog.borovsak.si

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list





[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux