
samir.gambler
New User
Nov 22, 2011, 10:21 PM
Post #2 of 3
(1669 views)
|
|
Re: [samir.gambler] Need to implement threading concept
[In reply to]
|
Can't Post
|
|
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; } 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)
|