Re: is the GSList library MT safe ?
- From: Owen Taylor <otaylor redhat com>
- To: gtk-devel-list redhat com
- Subject: Re: is the GSList library MT safe ?
- Date: 26 Nov 1999 23:39:43 -0500
Sebastien Rougeaux <Sebastien.Rougeaux@syseng.anu.edu.au> writes:
> I am wondering if the GSList utility provided by glib is really
> Multi-Thread safe. Here is a little example that do simple list
> operations in two separate threads (for 2 separate lists), and
> that crashes all the time for me (using redhat 6.1, gtk+-1.2.5)
[...]
> int main(int argc, char *argv[]) {
> GSList *list=NULL;
> int i,n=30;
> pthread_t t_id;
>
> for (i=0;i<n;i++) list = g_slist_append(list,(gpointer *)i);
>
> if (pthread_create(&t_id, NULL, myLoop, (void *)NULL) == -1)
> perror("pthread_create");
>
> while (1) {
> list = g_slist_append(list,list->data);
> list = g_slist_remove(list,list->data);
> }
> return 0;
> }
Compile with glib-config --libs gthread and add a
call g_thread_init(NULL) at the beginning of
main(), and things should work better.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]