Unable to lock array 
Author Message
 Unable to lock array

Hi,

I am writing a multi-threaded program but am not able to share an array
between the threads.

I have a directory called "oltest" under which there are sub-directories,
which have files with the extension .ud. The script does a find in the
oltest directory to store all files with .ud extension in the array udList.

It spawns 6 threads and my initial intention is that each thread should grab
(by shift) one file name from the list and print it. But all 6 threads are
printing the same file name. What is the fix for this?

The final intention is to get all the files in the list. As each thread gets
a file, which is a test case in a regression suite, it will pass it to a
back end Tuxedo server.

Thanks,
-- Mah{*filter*}

===============================================================
use strict;
use File::Find;
use Thread;



sub runUd {
        my $udNum;

                {


                        my $tid = Thread->self->tid;
                        print "thread $tid: $ud\n";
                }
        }
        else {
                return;
        }

Quote:
}


for my $i (1..6) {

Quote:
}


        $t->join();
Quote:
}



Tue, 22 Nov 2005 12:50:41 GMT  
 Unable to lock array

Quote:

> Hi,

> I am writing a multi-threaded program but am not able to share an array
> between the threads.

Are you stuck with 5005threads, or can you use ithreads?

If you don't need to use 5005threads you should stop using the Thread module
which is labelled "for old code only".

I don't pretend to know anything about perl threading and so don't know

share data by default according to the docs).

Can you use the Thread::Queue module?

It would do all the locking stuff for you, and would also allow you to
run the File::Find as a thread (and hence in parallel) safely.

[snip]

Quote:
> use strict;
> use File::Find;
> use Thread;



> sub runUd {
>         my $udNum;

>                 {


>                         my $tid = Thread->self->tid;
>                         print "thread $tid: $ud\n";
>                 }
>         }

That locking is faulty, in that a bunch of threads will end up shifting
from an empty array. If that's OK then I guess it doesn't really count as
a fault. If it isn't then you should be checking the length after the lock.

--
Sam Holden



Tue, 22 Nov 2005 13:10:12 GMT  
 Unable to lock array
Why not do the 'shift udList' in the outer loop and pass the name into the
threaded process?

Quote:

> It spawns 6 threads and my initial intention is that each thread should
> grab (by shift) one file name from the list and print it. But all 6
> threads are printing the same file name. What is the fix for this?

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


Wed, 23 Nov 2005 19:57:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Unable to Lock password file

2. Unable to lock password file

3. Unable to Lock password file

4. Unable to access an array from within a class

5. Unable To Display Updated Array Contents In Window

6. ".lock"-style locking module?

7. Emacs cperl-mode.el vs font-lock/lazy-lock

8. PERLFUNC: lock - get a thread lock on a variable, subroutine, or method

9. PERLFUNC: flock - lock an entire file with an advisory lock

10. PERLFUNC: flock - lock an entire file with an advisory lock

11. PERLFUNC: lock - get a thread lock on a variable, subroutine, or method

12. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

 

 
Powered by phpBB® Forum Software