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;
daniel

In reply to Responsive GUI without threads by ruoso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.