Thanks Jerry and Bill for the input...
So evaluating this code what can I do to get a solution in place?
while (1) {
eval { mkpath([EMAIL PROTECTED], 1, 0777) };
if ($@) {
print "Could not create: $@";
}
print "\n[INFO:: [MAINTHREAD] :: QUEUE MONITOR -> NO FILES TO
PROCESS]\n\n";
if (!($dbh = DBI->connect('dbi:ODBC:$db, '$user', '$pass'))) {
print "[WARNING :: [MAINTHREAD] :: DATABASE CURRENTLY
UNAVAILABLE]\n";
} else {
opendir (QUEUE, $Local_Directories[1]) or report ("Unable to
open $!\n");
while (defined (my $file = readdir (QUEUE)) ) {
if ($file =~ m/^\d{5}/) {
$thr = threads->create(\&prepPackage,$file);
}
}
closedir(QUEUE);
}
sleep(900);
}
So for each job that comes into a queue, I am spawning a new $thr... I
am wandering if maybe I need to do something different here with the
variable name and have each thread have its own thread ID... So instead
of just simply calling $thr, maybe I could parse out the first 5 digits
of the file and use that as a new thread...
I apologize for this architectural question, but how would I keep up
with the threads and have them monitor themselves for a timeout value?
Thank you in advance
Dan J. Rychlik
-----Original Message-----
From: Jerry D. Hedden [mailto:[EMAIL PROTECTED]
Sent: Friday, May 05, 2006 8:16 AM
To: Daniel Rychlik
Cc: [email protected]; [email protected]
Subject: RE: Intresting Logic Problem
> I have just discovered a serious issue within the core
> architecture of this beast of a program that I have
> written using threads...
>
> I am using Thread::Queue to throttle resources from the
> jobs that have to be done at any given time.
>
> This program, collects information from a database, maps a
> drive using OLE calls, and copies the files to the
> destination drive and it does this part well. The problem
> is, some of my servers are dial up... I have no issues
> making modem calls but sometimes I get disconnected during
> the copy phase which causes my threads to hold up and not
> release its resource back to the queue for the next job...
>
> I am limited on resources for the jobs...
>
> Right now, I am simply passing the job off to a thread and
> detaching it... If for some reason, like being
> disconnected from the server, the thread hangs out there
> in lala land and never returns it resource back to the
> resource queue for the next job, causing a major
> bottleneck in my program.
>
> I am inquiring about a possible solution to monitor either
> connection status to my destination server, or a thread
> timeout so that I can catch the resource and put it back
> in the queue for the next job.
>
> Is there a way to do a thread timeout? If a thread
> doesn't respond within so many seconds, then run this
> function?
There is no 'thread timeout' functionality per se. Further,
there is no 'thread cancellation' functionality. Therefore,
threads must monitor their own activity and time themselves
out, if required. Note that you cannot use alarm() for this
purpose. If IO is involved, you need to use select() with
an appropriate timeout to accomplish your purpose.