in reply to Event module and threads/fork segfault on Win32
Since Event is an event loop system, I looked at it like I would a Tk or Gtk2 threaded program. In Tk, the thread must be created before any event-loop code( i.e. Tk statements ) are made, so the following seems to work for me.
#!/usr/bin/perl use strict; use warnings; use threads; my $thr = async { for(1..10){ warn "in thread $_\n"; sleep 1; } }; sub create_thread { warn "in create_thread() before async()\n"; # my $thr = async { warn "in thread\n"; }; warn "in create_thread() before join()\n"; sleep 2; $thr->join; warn "in create_thread() before return\n"; return; } use Event; my $timer = Event->timer( cb => \&create_thread, after => 2); warn "starting event loop\n"; Event::loop;
Gtk2 has a thread-safety mechanism, that does allow you to create threads after event-loop code has been written. So you might want to try Gtk2 and it's GLib. However, even some Gtk2 experts say it is still better to create your threads first, before any Gtk2 code is written. See Roll your own Event-loop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Event module and threads/fork segfault on Win32
by gurbo (Sexton) on Jun 05, 2007 at 14:20 UTC | |
by zentara (Cardinal) on Jun 05, 2007 at 16:32 UTC | |
by gurbo (Sexton) on Jun 07, 2007 at 02:58 UTC |