develooper Front page | perl.ithreads | Postings from March 2008

Time to cancel a thread

Thread Next
Javier Terceiro
March 24, 2008 16:24
Time to cancel a thread
Message ID:
Hello list,

I am writing a daemon. I have a daemon that it check a folder and then
throws both threads exist as files. It's well, the problem is that
each thread need it ends at a certain time (defined by default). If
this does not complete the work to be cancelled. For example, if it is
making a connection to a website and it does not respond in 2 minutes,
until the process completes and the thread too, running a particular
code before.

I was looking like doing and I did not find anything. Any thoughts on
how to do that

My source code is:

#!/usr/bin/perl -w

use strict;
use warnings;
use AnyData;
use Sys::Syslog qw(:standard :macros);
use POSIX qw(setsid);
use threads;
use threads::shared;

sub mail
        syslog LOG_INFO, "thread for mail";
        my $file_name = shift;
	# If you spent 2 min, canceled
	# source cancel
	syslog LOG_INFO, "Surpassed time";

	# else
	syslog LOG_INFO, "Process completed";

sub scan_files
        my $DIR = "workq/";
                opendir(DIRHANDLE, $DIR) || die "ERROR: $DIR not read\n";
                foreach (readdir(DIRHANDLE))
                        if (!-d $_)
				threads->new(\&mail, $_);
                closedir DIRHANDLE;

A greeting,


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About