In Re^3: Parrot, threads & fears for the future., merlyn pointed that if "threads" is the answer, you asked the wrong question. For some tasks I do agree, some implementations does exceed the use of threads where forking could solve the same problem without the implicit problems of using threads. But one task still seems to me like one where "threads" is indeed the answer, which is making a responsive Graphical User Interface.
Considering the following code (currently without threads and, like that, unresponsive). How one could make that responsive without threads?
#!/usr/bin/perl use strict; use warnings; use Glib qw/TRUE FALSE/; use Gtk2 -init; # Code taken from Perl Gtk2 tutorial with some modifications... # http://gtk2-perl.sourceforge.net/doc/gtk2-perl-tut/sec-Statusbars.ht +ml my $window = Gtk2::Window->new('toplevel'); $window->set_size_request(200, 100); $window->set_title("gtk2-perl Statusbar Example"); $window->signal_connect(delete_event => sub { Gtk2->main_quit; FALSE; +}); my $vbox = Gtk2::VBox->new(FALSE, 1); $window->add($vbox); $vbox->show; my $status_bar = Gtk2::Statusbar->new; $vbox->pack_start($status_bar, TRUE, TRUE, 0); $status_bar->show; $status_bar->{count} = 1; my $context_id = $status_bar->get_context_id("Statusbar example"); my $button = Gtk2::Button->new("push item"); $button->signal_connect(clicked => sub { $status_bar->push($context_id, sprintf("Starting... Item %d", $status_bar-> +{count}++)); sleep 10; # some lenghty task $status_bar->pop($context_id); }); $vbox->pack_start($button, TRUE, TRUE, 2); $button->show; $window->show; Gtk2->main;
In reply to Responsive GUI without threads by ruoso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |