CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [samir.gambler] Need to implement threading concept: Edit Log

New User

Nov 22, 2011, 10:21 PM

Views: 2290
Re: [samir.gambler] Need to implement threading concept

I have tried to implement the case mentioned above but still i have some issue.

use Thread qw(async);  
use threads::shared;

my $a :shared;
$a = 1;
$thr1 = async {
my $b;
lock ($a);
$b = $a;
opendir (DIR, "C:\\temp");
my @filelist = grep (!/^\./, grep(-r, readdir(DIR)));
print ("file content is @filelist ");
close DIR;
exit "ERROR: file found!!\n" if (@filelist>0);
lock ($a);
$b = $a;
print ("Value of a is $a\n");

sleep (2);
lock ($a);
$a = 2;
print "\nSam EXP\n";

If any file is found in the directory then i am exiting..... till here it is ok. But if the file is not found in the directory and my rest of the program comes to an end then i want to stop the thread by changing the value of a shared variable $a, but it seems the new value of $a is not received by the thread. Can you please have a look at it and point out what I am doing wrong.

(This post was edited by samir.gambler on Nov 22, 2011, 10:23 PM)

Edit Log:
Post edited by samir.gambler (New User) on Nov 22, 2011, 10:23 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives