Madhu Reddy wrote:

> hi,
>   I just want to find out how and when to use locks in
> threads...
> i have following program..
> in following %bounds is global variable....
> each thread will update %bounds....
> and later i am using %bounds...
> 
> do i have lock the %bounds before each thread update ?
> 
> 
> my %bounds = ();
> 
> 

by default, %bounds is not shared among threads (local variable is not 
shared among threads), you have to tell Perl that you want to share it 
like:

use threads::shared;

my %bounds : shared = ();

now that %bounds is shared, you need to lock it when you update/access 
%bounds. again you have to tell Perl that you want to lock it like:

{
        lock(%bounds);
        #-- do something with %bounds
}

#-- unlock when block exit

the bare block is important, Perl unlocks %bounds automatically when the 
block exit.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to