On 29/07/07, zentara <zentara1 sbcglobal net> wrote:
With Gtk2, you have Glib's thread safety mechanism, SO.... you do not have to create the thread before any widgets. ( Although it is safer).
Ahh. I hadn't spotted the Glib::Object->set_threadsafe (TRUE); line. I can create the thread immediately before the mainloop and in an anonymous sub and it seems bulletproof. (ThreadDemo2.pl) Strangely, if I create the thread in the callback to the start button, I get problems (ThreadDemo3.pl). As written, I get: Attempt to free unreferenced scalar: SV 0x877dc0c, Perl interpreter: 0x8152008 at ./ThreadDemo3.pl line 54. when quitting. If I move the entire callback into a named sub, I get: GLib-GObject-WARNING **: instance of invalid non-instantiatable type `-g-type-private--GTypeFlags'. GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed. GLib-GObject-WARNING **: instance of invalid non-instantiatable type `-g-type-private--GTypeFlags'. GLib-GObject-CRITICAL **: g_signal_handlers_destroy: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed. GLib-GObject-WARNING **: instance of invalid non-instantiatable type `-g-type-private--GTypeFlags'. GLib-GObject-CRITICAL **: g_signal_handlers_destroy: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed. When quitting. I see in Feb, you were having the same problems, which Glib::Object->set_threadsafe (TRUE); fixed for you (http://mail.gnome.org/archives/gtk-perl-list/2007-February/msg00014.html)
There are examples around, where you launch new threads with a button press.
I haven't seen any that work. Would you mind giving me a couple of links?
You're right, AFAICT, BUT you can try to pass code to be executed to a thread, through a shared variable, then eval it in the thread.
That is an interesting idea I hadn't thought of. When I try it (ThreadDemo4.pl), I get GLib-CRITICAL **: g_hash_table_foreach: assertion `hash_table != NULL' failed at ./ThreadDemo4.pl line 23. on launching the app. But it almost works! On hitting the start button, it gets to 75% and then locks. Time to get some sleep. Jeff
Attachment:
ThreadDemo2.pl
Description: Perl program
Attachment:
ThreadDemo3.pl
Description: Perl program
Attachment:
ThreadDemo4.pl
Description: Perl program