Re: New objects for GLib



Sebastian Wilhelmi <wilhelmi@ira.uka.de> writes:

> I looked at the code. Actually there are so many lock calls here, that I'm not
> sure it really is faster anymore. So I tried it. Here are the results. The
> program is appended. It should work with CVS GLib. 
> 
> And there it turns out, that your solution is (noticably) slower than mine
> (which indeed also baffles me a bit, so there might be an error in the
> comparision, please check). Also it seems that lac_queue_read(bla, FALSE) will
> not work, if another thread is already waiting.

You are right, your queue is much faster, except on Irix. Perhaps
Irix's mutexes are very fast?

I tried your program with the version of LacQueue that doesn't allow
more than one reader/writer. As expected, my queue is faster.

Your unmodified test program gives me:

dodeca:~/tmp% uname -a
IRIX64 dodeca 6.5 10181059 IP27 mips
dodeca:~/tmp% gcc `glib-config --cflags` queue-compare.c `glib-config --libs gthread`
dodeca:~/tmp% a.out
pushing 100000 elements into LacQueue: 0.517876 seconds
popping 100000 elements from LacQueue: 0.455735 seconds
pushing 100000 elements into GAsyncQueue: 1.340939 seconds
popping 100000 elements from GAsyncQueue: 1.341068 seconds

With more elements I get

dodeca:~/tmp% a.out
pushing 500000 elements into LacQueue: 2.258968 seconds
popping 500000 elements from LacQueue: 2.244007 seconds
pushing 500000 elements into GAsyncQueue: 6.722494 seconds
popping 500000 elements from GAsyncQueue: 6.723236 seconds

This is on Irix. 

On RedHat 6.1 I found that your queue is much faster. This is also
true on Solaris, but with a twist:

sunbird:~/extra2/glib% queue-compare 
popping 500000 elements from LacQueue: 4.861091 seconds
pushing 500000 elements into LacQueue: 4.902817 seconds
pushing 500000 elements into GAsyncQueue: 2.497430 seconds
popping 500000 elements from GAsyncQueue: 2.579769 seconds

This is when the mutexes are created with USYNC_PROCESS. When they are
created with USYNC_THREAD, I get:

sunbird:~/extra2/glib% queue-compare 
pushing 500000 elements into LacQueue: 3.803957 seconds
popping 500000 elements from LacQueue: 3.835643 seconds
pushing 500000 elements into GAsyncQueue: 2.737065 seconds
popping 500000 elements from GAsyncQueue: 2.716155 seconds

Do GLib mutexes have to be able to synchronize threads in different
processes? If not, then why not do

Index: gthread/gthread-solaris.c
===================================================================
RCS file: /cvs/gnome/glib/gthread/gthread-solaris.c,v
retrieving revision 1.8
diff -u -r1.8 gthread-solaris.c
--- gthread/gthread-solaris.c   2000/03/17 14:49:59     1.8
+++ gthread/gthread-solaris.c   2000/04/18 19:24:55
@@ -66,7 +66,7 @@
 g_mutex_new_solaris_impl (void)
 {
   GMutex *result = (GMutex *) g_new (mutex_t, 1);
-  solaris_check_for_error (mutex_init ((mutex_t *) result, USYNC_PROCESS, 0));
+  solaris_check_for_error (mutex_init ((mutex_t *) result, USYNC_THREAD, 0));
   return result;
 }

Condition variables are already created with USYNC_THREAD.

> /* Compile with latest CVS Glib: e.g.
> 
>       gcc -I. -o queue-compare queue-compare.c .libs/libglib.a \
>          gthread/.libs/libgthread.a -lpthread

The CVS version of GLib was unable to find out that it must use
-lpthread on Irix. It seems pthread_create is available without
-lpthread while the other pthread functions are not.

This patch may fix it, but I don't know much about autoconf.

Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.128
diff -u -r1.128 configure.in
--- configure.in        2000/04/17 13:23:27     1.128
+++ configure.in        2000/04/18 17:51:54
@@ -758,13 +758,16 @@
 
                        LIBS="$glib_save_LIBS $add_thread_lib"
 
-                       AC_MSG_CHECKING(for pthread_create$IN)
+                       AC_MSG_CHECKING(for pthread_join$IN)
                        AC_TRY_RUN([#include <pthread.h> 
                                void* func(void* data) {}
                                 main()
                                { pthread_t t; 
-                                 exit(pthread_create (&t, $defattr, func, 
-                                               NULL));
+                                 if (pthread_create (&t, $defattr, func, 
+                                                     NULL) != 0)
+                                   exit (1);
+                                 exit (pthread_join (t, NULL));
                                }],
                                [AC_MSG_RESULT(yes)
                                G_THREAD_LIBS="$add_thread_lib"



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