Z
ziemo
Hello,
I need to create 10 threads. When one of them finished work, the next
thread will be start.
I have a problem with memory leak. After couple minute my RAM is full.
Could someone suggest where is the problem or how I can solve my
problem with another method?
Sory for my english and thanks for help
ziemo
#!/usr/bin/perl -w
use strict;
use threads;
use threads::shared;
use Thread::Queue;
my $koniec : shared = 1;
my $ilosc_watkow=10;
my $count : shared;
my $end : shared;
my $kon = new Thread::Queue;
while($koniec){
$count = 0;
if($count < 1000){
$end=0;
threads->create(\&watek2) for
1..$ilosc_watkow;
while(!$end){
while($kon->pending){
threads->object($kon->dequeue)-
$end;
}
sleep 1;
}
foreach my $thr (threads->list){
if ($thr->tid && !threads::equal($thr,
threads->self)) {
$thr->join;
}
}
}
sleep 5;
}
sub watek2 {
if(!$end){
if($count<1000){
print $count."\n";
lock $count;
$count++
} else {
lock($end);
$end = 1;
}
}
$kon->enqueue(threads->self->tid);
}
I need to create 10 threads. When one of them finished work, the next
thread will be start.
I have a problem with memory leak. After couple minute my RAM is full.
Could someone suggest where is the problem or how I can solve my
problem with another method?
Sory for my english and thanks for help
ziemo
#!/usr/bin/perl -w
use strict;
use threads;
use threads::shared;
use Thread::Queue;
my $koniec : shared = 1;
my $ilosc_watkow=10;
my $count : shared;
my $end : shared;
my $kon = new Thread::Queue;
while($koniec){
$count = 0;
if($count < 1000){
$end=0;
threads->create(\&watek2) for
1..$ilosc_watkow;
while(!$end){
while($kon->pending){
threads->object($kon->dequeue)-
threads->create(\&watek2) if !join;
$end;
}
sleep 1;
}
foreach my $thr (threads->list){
if ($thr->tid && !threads::equal($thr,
threads->self)) {
$thr->join;
}
}
}
sleep 5;
}
sub watek2 {
if(!$end){
if($count<1000){
print $count."\n";
lock $count;
$count++
} else {
lock($end);
$end = 1;
}
}
$kon->enqueue(threads->self->tid);
}