public inbox for guile-gtk@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: guile-gtk@sources.redhat.com
Subject: gdk_threads_enter versus sgtk_init_threads
Date: Sat, 24 May 2003 00:09:00 -0000	[thread overview]
Message-ID: <87d6i9jjd5.fsf@zip.com.au> (raw)

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

             reply	other threads:[~2003-05-24  0:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-24  0:09 Kevin Ryde [this message]
2003-05-30  1:46 ` Kevin Ryde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d6i9jjd5.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-gtk@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).