[Gtk-sharp-list] Threads safety?

John Luke John Luke <john.luke@gmail.com>
Fri, 27 Aug 2004 14:19:41 -0400


Hello,

If it works on linux but not on win32, then it is a bug.  Whether it
is a GTK+ or Gtk# one I dont yet know. It would be best to file a bug
in Gtk#, and let them pass it to GTK if it is. You can alternatively
look for the GTK+ threading faq on gtk.org, and look into using
Gtk.ThreadNotify or GLib.Idle.

Hope that helps

On Mon, 23 Aug 2004 21:35:09 +0200, Freon <freongrr@gmail.com> wrote:
> Hi,
>=20
> I'm very new to gtk, so this question might seem trivial to some of
> you, it shouldn't be too hard answering it then ;)
> My application crashes when I'm adding new widgets (tabs for
> instance). After some searching around I've found out it happens
> because I create the widgets in a callback. In the gtk# doc it saids I
> need to use Gdk.Threads.Enter() and Gdk.Threads.Enter(), but it still
> doesn't work :( My application still crashes with various error
> messages or visual results).
>=20
> I made the simplest test possible and it still doesn't work. Shouldn't
> something like this work on Windows?? I tried under Linux and it works
> perfectly.
>=20
> // ----------------------------------------------------------
> using System;
> using System.Threading;
> using Gtk;
>=20
> public class TestThread
> {
> static void Main (string[] args)
> {
> Window window;
>=20
> GLib.Thread.Init(); // .NET needs that...
> Gdk.Threads.Init ();
> Gtk.Application.Init ();
>=20
> window =3D new Window ("Sample");
> window.Show ();
>=20
> Thread t =3D new Thread(new ThreadStart(grr));
> t.Start();
>=20
> Gdk.Threads.Enter();
> Gtk.Application.Run();
> Gdk.Threads.Leave();
> }
>=20
> public static void grr()
> {
> System.Threading.Thread.Sleep(1000);
> Gdk.Threads.Enter();
> Window win =3D new Window("arf");
> Button b =3D new Button("grr");
> win.Add(b);
> win.ShowAll();
> Gdk.Threads.Leave();
> }
> }
> // ----------------------------------------------------------
>=20
> That code ran under Windows (with .NET or Mono) produces this output:
>=20
> (<unknown>:476): Gdk-WARNING **: [Invalid UTF-8]
> gdkpixmap-win32.c:196: GetDC failed: Handle de fen=DBtre non valide.
>=20
> (<unknown>:476): Gdk-WARNING **: [Invalid UTF-8]
> gdkpixmap-win32.c:111: DeleteObject failed: Op=DAration r=DAussie.
>=20
> (<unknown>:476): Gdk-CRITICAL **: file gdkgc.c: line 90
> (gdk_gc_new_with_values): assertion `drawable !=3D NULL' failed
>=20
> (<unknown>:476): Gdk-CRITICAL **: file gdkgc-win32.c: line 643
> (gdk_gc_set_clip_region): assertion `GDK_IS_GC (gc)' failed
>=20
> (<unknown>:476): Gdk-CRITICAL **: file gdkdraw.c: line 410
> (gdk_draw_rectangle): assertion `GDK_IS_DRAWABLE (drawable)' failed
>=20
> (<unknown>:476): GLib-GObject-CRITICAL **: file gobject.c: line 1337
> (g_object_unref): assertion `G_IS_OBJECT (object)' failed
>=20
> (<unknown>:476): Gdk-CRITICAL **: file gdkdraw.c: line 410
> (gdk_draw_rectangle): assertion `GDK_IS_DRAWABLE (drawable)' failed
>=20
> Any idea?
>=20
> Also, on the doc
> (http://www.go-mono.com/docs/monodoc.ashx?tlink=3D6@ecma%3a399%23Threads%=
2f)
> it says it's a good idea to call "gdk_flush()" before Threads.Leave(),
> I guess it's the C gtk name, how was it called in gtk#? o_O
>=20
> Thanks in advance :)
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>