Prev: FAQ 3.26 Where can I learn about object-oriented Perl programming?
Next: FAQ 6.2 I'm having trouble matching over more than one line. What's wrong?
From: michael20545 on 8 Aug 2010 13:23 Hi all, I often need to convert 100s of SVG files to EPS format with Inkscape. It is continuous process, so I decided to use Perl threads for performing several jobs simultaneously. I'm new to Perl threads. Here is my script. use strict; use threads; use threads::shared; use Cwd; my $i : shared =0; my $dir=getcwd(); my @files=<*.svg>; threads->new(\&convert_to_eps,1)->join(); threads->new(\&convert_to_eps,2)->join(); threads->new(\&convert_to_eps,3)->join(); sub convert_to_eps { my $thread_num=$_[0]; while($i<=$#files) { my $svg=$files[$i++]; my $eps=$svg; $eps=~ s/\.svg/.eps/; print "$thread_num $svg\n"; `inkscape -f "$dir\\$svg" -T -C -E "$dir\\$eps"`; } } Here works only first thread. What is wrong? Thanks, Michael. --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Martijn Lievaart on 8 Aug 2010 13:37 On Mon, 09 Aug 2010 00:23:42 +0700, michael20545 wrote: > Hi all, > > I often need to convert 100s of SVG files to EPS format with Inkscape. > It is continuous process, so I decided to use Perl threads for > performing several jobs simultaneously. I'm new to Perl threads. Here is > my script. (...) > threads->new(\&convert_to_eps,1)->join(); This creates a new thread and waites until it is finished. > threads->new(\&convert_to_eps,2)->join(); > threads->new(\&convert_to_eps,3)->join(); # error handling omited my @threads; push @threads, threads->new(\&convert_to_eps,$_) for (1 2 3); $_->join() for @threads; HTH, M4
From: michael20545 on 8 Aug 2010 14:54 09.08.2010 00:37, Martijn Lievaart пишет: > On Mon, 09 Aug 2010 00:23:42 +0700, michael20545 wrote: > >> Hi all, >> >> I often need to convert 100s of SVG files to EPS format with Inkscape. >> It is continuous process, so I decided to use Perl threads for >> performing several jobs simultaneously. I'm new to Perl threads. Here is >> my script. > > (...) > >> threads->new(\&convert_to_eps,1)->join(); > > This creates a new thread and waites until it is finished. > >> threads->new(\&convert_to_eps,2)->join(); >> threads->new(\&convert_to_eps,3)->join(); > > # error handling omited > > my @threads; > > push @threads, threads->new(\&convert_to_eps,$_) for (1 2 3); > $_->join() for @threads; > > HTH, > M4 Thank you Martijn! Another question: I want to use these threads in another work; so I should wait until all threads' work is done. How to determine it? --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Xho Jingleheimerschmidt on 8 Aug 2010 14:59 michael20545 wrote: > Hi all, > > I often need to convert 100s of SVG files to EPS format with Inkscape. > It is continuous process, so I decided to use Perl threads for > performing several jobs simultaneously. I'm new to Perl threads. Here is > my script. > > > use strict; > use threads; > use threads::shared; > use Cwd; > my $i : shared =0; > my $dir=getcwd(); > my @files=<*.svg>; > threads->new(\&convert_to_eps,1)->join(); This waits for the first thread to finish, at which time later threads have nothing left to do. Xho
From: Willem on 8 Aug 2010 15:01
michael20545 wrote: ) 09.08.2010 00:37, Martijn Lievaart ??????????: )> my @threads; )> )> push @threads, threads->new(\&convert_to_eps,$_) for (1 2 3); )> $_->join() for @threads; ) ) Thank you Martijn! Another question: I want to use these threads in ) another work; so I should wait until all threads' work is done. How to ) determine it? Already done. The for-loop joins all the threads. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT |