From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7201 invoked by alias); 24 May 2003 00:09:44 -0000 Mailing-List: contact guile-gtk-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: guile-gtk-owner@sources.redhat.com Received: (qmail 7144 invoked from network); 24 May 2003 00:09:43 -0000 Received: from unknown (HELO snoopy.pacific.net.au) (61.8.0.36) by sources.redhat.com with SMTP; 24 May 2003 00:09:43 -0000 Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.3) with ESMTP id h4O09fPB010319 for ; Sat, 24 May 2003 10:09:41 +1000 Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h4O09eQg016187 for ; Sat, 24 May 2003 10:09:40 +1000 (EST) Received: from localhost (ppp126.dyn228.pacific.net.au [203.143.228.126]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h4O09cYZ017853 for ; Sat, 24 May 2003 10:09:39 +1000 (EST) Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19JMbH-0001z4-00; Sat, 24 May 2003 10:09:27 +1000 To: guile-gtk@sources.redhat.com Subject: gdk_threads_enter versus sgtk_init_threads From: Kevin Ryde Mail-Copies-To: never Date: Sat, 24 May 2003 00:09:00 -0000 Message-ID: <87d6i9jjd5.fsf@zip.com.au> User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2003-q2/txt/msg00100.txt.bz2 --=-=-= Content-length: 1481 I believe sgtk_init_threads is being called too late to influence gdk_threads_enter and gdk_threads_leave, and that instead they're ending up as noops. The program threads.scm below illustrates the problem, threads 1, 2 and 3 are able to "enter" all at the same time. I've using a recent i386 debian with the guile cvs and pthreads for this, 1 entering 1 entered 2 entering 2 entered 3 entering 3 entered ... Adding a printf of gdk_threads_mutex to the generated sgtk_gdk_threads_enter reveals NULL. I'm pretty sure gtk_init has called gdk_init which has initialized it's threading before sgtk_init_threads has had a chance to setup the glib level stuff. I get some joy from moving the sgtk_init_threads call from sgtk_init_substrate to the start of sgtk_init_with_args (before gtk_init). This exposes however that gdk-threads-enter shouldn't be using SCM_DEFER_INTS, since of course it needs other threads to run to release the mutex. * gdk-1.2.defs (gdk_threads_enter, gdk_threads_leave): Add undeferred, since these are thread safe, and in particular enter needs other threads runnable to release the mutex. * guile-gtk.c (sgtk_init_substrate): Move sgtk_init_threads .... (sgtk_init_with_args): ... to here, to ensure glib threading is setup before gtk_init and gdk_init run. It might be nice if the glib level inits were separated, for clarity. Perhaps that can wait until there's an actual glib module though. --=-=-= Content-Disposition: attachment; filename=threads.scm Content-length: 575 (use-modules (ice-9 threads) (gtk gtk) (gtk gdk)) (begin-thread (display "1 entering\n") (gdk-threads-enter) (display "1 entered\n") (sleep 2) (display "1 leaving\n") (gdk-threads-leave) (display "1 left\n")) (begin-thread (display "2 entering\n") (gdk-threads-enter) (display "2 entered\n") (sleep 2) (display "2 leaving\n") (gdk-threads-leave) (display "2 left\n")) (begin-thread (display "3 entering\n") (gdk-threads-enter) (display "3 entered\n") (sleep 2) (display "3 leaving\n") (gdk-threads-leave) (display "3 left\n")) (sleep 20) --=-=-= Content-Disposition: attachment; filename=guile-gtk.c.threads.diff Content-length: 525 --- guile-gtk.c.~1.15.~ 2003-05-24 10:02:45.000000000 +1000 +++ guile-gtk.c 2003-05-24 10:02:57.000000000 +1000 @@ -2774,8 +2774,6 @@ callback_trampoline = scm_permanent_object (scm_cons (SCM_BOOL_F, SCM_EOL)); - sgtk_init_threads (); - #ifndef SCM_MAGIC_SNARFER #ifndef MKDEP #include "guile-gtk.x" @@ -2795,6 +2793,8 @@ been initialized when Gdk has. That is not completely correct, but the best I can do. */ + sgtk_init_threads (); + if (gdk_display == NULL) { gtk_set_locale (); --=-=-= Content-Disposition: attachment; filename=gdk-1.2.defs.undefer.diff Content-length: 303 --- gdk-1.2.defs.~1.28.~ 2003-05-19 10:26:58.000000000 +1000 +++ gdk-1.2.defs 2003-05-23 14:58:39.000000000 +1000 @@ -1737,11 +1737,13 @@ (define-func gdk_threads_enter none - ()) + () + (undeferred #t)) (define-func gdk_threads_leave none - ()) + () + (undeferred #t)) ;; gdkrgb --=-=-=--