Leser: 19
QuoteTk::Error: Usage: threads->exit(status) at scripts\GUI.pl line 63
Tk callback for .frame2.button1
Tk::__ANON__ at C:/P/site/lib/Tk.pm line 250
Tk::Button::butUp at C:/P/site/lib/Tk/Button.pm line 175
<ButtonRelease-1>
(command bound to event)
1
2
3
4
5
6
7
8
9
10
11
12
my $Button2 = $frame3->Button (-text=> "Start",-command =>sub{
my $thread = threads->create(\&startProcessing);
});
my $Button = $frame3->Button (-text=> "Exit",-command =>sub{
my @running = threads->list(threads::running);
foreach (@running) {
my $tid = $_->tid();
print "Killing Thread $tid \n";
$_->exit();
}
exit(0);
});
MyThreads::do { $_->kill('KILL')->detach };
1
2
3
4
5
6
my @threads = ();
push @threads, threads->create(\&getData)->detach();
push @threads, threads->create(\&read1)->detach();
push @threads, threads->create(\&read2)->detach();
push @threads, threads->create(\&read3)->detach();
push @threads, threads->create(\&read4)->detach();
1 2
sub thr1 { lock($x); sleep 1; lock($y); } sub thr2 { lock($y); sleep 1; lock($x); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use Thread::Queue;
my $control_queue = new Thread::Queue;
.
.
.
#Auf Knopfdruck:
$control_queue->enqueue('stop');
#Im Thread dann irgendwo die queue abfragen und auf Kommando aussteigen
sub mythread {
while (! $exit) {
.
.
.
if ($control_queue->pending) {
if($control_queue->dequeue eq 'stop') {
$exit=1;
}
}
threads->detach();
}
QuoteTk is not thread safe, but you can use threads with it with precautions.
1. The thread must be created before any Tk widgets are invoked. You violate that rule by creating the thread in a button callback.
2. Do not put any Tk code into the thread, and do not try to access Tk widgets from the thread. Use shared variables to communicate with the main thread, and have a timer or fileevent in the main Tk thread, read from the thread.