public inbox for guile-gtk@sourceware.org
 help / color / mirror / Atom feed
* gdk_threads_enter versus sgtk_init_threads
@ 2003-05-24  0:09 Kevin Ryde
  2003-05-30  1:46 ` Kevin Ryde
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Ryde @ 2003-05-24  0:09 UTC (permalink / raw)
  To: guile-gtk

[-- Attachment #1: Type: text/plain, Size: 1481 bytes --]

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.


[-- Attachment #2: threads.scm --]
[-- Type: text/plain, Size: 575 bytes --]

(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)

[-- Attachment #3: guile-gtk.c.threads.diff --]
[-- Type: text/plain, Size: 525 bytes --]

--- 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 ();

[-- Attachment #4: gdk-1.2.defs.undefer.diff --]
[-- Type: text/plain, Size: 303 bytes --]

--- 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
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gdk_threads_enter versus sgtk_init_threads
  2003-05-24  0:09 gdk_threads_enter versus sgtk_init_threads Kevin Ryde
@ 2003-05-30  1:46 ` Kevin Ryde
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Ryde @ 2003-05-30  1:46 UTC (permalink / raw)
  To: guile-gtk

I wrote:
>
>         * 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.

I made this change.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-05-30  1:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-24  0:09 gdk_threads_enter versus sgtk_init_threads Kevin Ryde
2003-05-30  1:46 ` Kevin Ryde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).