We have an application running on Perl/gtk and it uses threads and threads::shared. Last night in the Freenode Perl IRC channel I learned that threads are not the best way to do 'threaded' programming in Perl.

why did we use threads?

Our single-threaded GUI app was freezing whenver we did dateabase reads and it looked like the app had crashed. Therefore we threaded the app and visual response significantly improved.

What alternatives are there to our problem

Glib already has threads

Khisanth pointed out that Glib (something used in Gtk2) has threads, so perhaps we should have been using those?

POE, AnyEvent, IO::Async

mst mentioned these as viable alternatives to threads. However, I could not persuade him to compare/contrast threads with these solutions for pros/cons.

perl threads are nearly forks anyway

From what I can see Perl threads make a copy of everything in the parent thread unless it is marked as shared.

How to achieve our goals

We mainly want our GUI app to remain responsive during background tasks and so we have a homegrown version of Thread::Queue (not my choice) which we use to queue and dequeue our data(base)? processing without tying up the mainloop of our gtk app. What other solutions exists for this problem and what are the pros/cons of this solution compared to Perl threads.

In reply to Alternatives to threads for maintaining GUI app responsiveness by metaperl

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.