<?xml version="1.0" encoding="windows-1252"?>
<node id="860078" title="How to pause multithreaded application?" created="2010-09-14 05:48:13" updated="2010-09-14 05:48:13">
<type id="115">
perlquestion</type>
<author id="510391">
Gangabass</author>
<data>
<field name="doctext">
I need a way to pause multithreaded Tkx application (threads are collecting some data via HTTP).

Threads push data to the queue so the main application can read it (and show to the user). Customer want to pause the program if one of the threads find some data. By pause i mean stop updating text log widget. Here is code:
&lt;c&gt;
sub start {

    my @result;

    $queue= Thread::Queue-&gt;new;
    $queue_processed = Thread::Queue-&gt;new;

    my @domains = get_domains($domains_filename);

    $queue-&gt;enqueue(@domains);

    my @threads= map { threads-&gt;create( sub { create_thread($_) } ) } ( 1 .. $CONFIG{NUMBER_OF_THREADS} );

    $_-&gt;detach for (@threads);

    my $counter = 0;

    while ( $counter &lt; scalar @domains ) {

    my $result = $queue_processed-&gt;dequeue_nb;

    if ($result) {

        $txt_processed_domains-&gt;configure(-state =&gt; "normal");
        $txt_processed_domains-&gt;insert_end( "$result" );
        $txt_processed_domains-&gt;see("end");
        $txt_processed_domains-&gt;configure(-state =&gt; "disabled");
        Tkx::update();
        $counter++;
    }
    }

    Tkx::tk___messageBox( -message =&gt; "Completed!" );
}
&lt;/c&gt;

So i have one problem: how to pause all running threads (and continue them after some user actions)?</field>
</data>
</node>
