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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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



samir.gambler
New User

Nov 22, 2011, 10:21 PM


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

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


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

my $a :shared;
$a = 1;
$thr1 = async {
my $b;
{
lock ($a);
$b = $a;
}
while($b==1)
{
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";
}
$thr1->join;



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.
Thanks.


(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