Thank you for the suggestions. I will do so moving forward. Reading through the Thread::Queue documentation it appears that it only works with scalars and not arrays or hashes or at least makes no mention of the use of arrays or scalars.
I would like to use Thread::Queue if that's what it takes. This program is a beast.... -----Original Message----- From: Mike Pomraning [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:27 AM To: Daniel Rychlik Cc: [email protected]; [email protected] Subject: RE: iThreads troubles On Wed, 19 Apr 2006, Daniel Rychlik wrote: > Some of you have asked for code examples. > > One of issues that I am having is when the thread enters into > getAvailableResource routine its not seeing that the > $Resources{'WAN1'}->{INUSE} = 1; has been made unavailable. The idea is > for the next thread to pick up the next unavailable resource. I tried > to sleep(1) between thread creation, and also used threads::shared > share(%Resources); which also failed. Dan, A few quick remarks/suggestions. First, please post the smallest possible code that reproduces your symptoms: pare down your problematic program, stuff it with stubs until you've got a cogent proof-of-problem. Second, &share()ing your hash clears it [0], so populate it /after/ you mark it shared. Additionally, the hash members themselves have to be explicitly shared, IIUC. [1] Third, your 'INUSE' check looks to have a race. You'll need to &lock(), use a semaphore, etc. As others have suggested, Thread::Queue makes these kinds of problems a lot easier. You could, perhaps, manage the "wan" and "modem" resources themselves in a queue -- pop off the next available one, use it, then re-queue it for another job later on. TMTOWTDI. [0] "When share is used on arrays, hashes, array refs or hash refs, any data they contain will be lost." http://search.cpan.org/~jdhedden/threads-shared-1.01/shared.pm#BUGS_AND_ LIMITATIONS [1] "This places restrictions on what may be assigned to shared array and hash elements: only simple values or references to shared variables are allowed..." http://www.perldoc.com/perl5.8.4/pod/perlthrtut.html#Shared-And-Unshared -Data Good luck, Mike -- cat: .signature: Message too long
