I tried that, but it's still doing as before. I'll give you a more fuller
outline of what there is, and what I want it to do, maybe it may become
clearer...
I'm using a socket, and it loops in a sub.
while (<SOCK>) {
    # etc..
}
once the code has finished connecting to the server, it runs another sub,
&ping,
sub ping {
    # blah blah
    if ($initial) {
        $thr = threads->new(\&akilltimeout);
        threads->yield;
        $thr->detach;
    }
}
as you see, this executes the sub &akilltimeout, which needs to run all the
time, which is,
sub akilltimeout {
    while (1) {
        # checks run here
        sleep 1;
    }
}
Now, when the code receives data from the server, the akilltimeout sub
executes, it sleeps for a second, then doesn't do anything else. When it
receives some more data, it executes again, etc. Basically, that sub needs
to be running, and the checks need to be made once every second, without
affecting the listening on the socket, since I know sleep() makes the entire
program wait. So i use threads to run this portion of code. But it isn't
running every second. Is this more clearer? Is this actually possible? heh

Many thanks once again for your help.

Dan

"Beau E. Cox" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi -
>
> > -----Original Message-----
> > From: dan [mailto:[EMAIL PROTECTED]]
> > Sent: Saturday, February 01, 2003 6:46 AM
> > To: [EMAIL PROTECTED]
> > Subject: Threads
> >
> >
> > Hey again,
> >
> > I have another problem, this time involving threads. Here's what
> > I intend to
> > do, and what I have in code (roughly).
> >
> > Basically, I want my program to run normally, but also have a while (1)
{
> > ... } loop going at the same time. This checks for things such as
expired
> > objects. The loop checks to see if $currtime >= $akill{$id}->{expires},
it
> > does this, but the way I activated the thread, it only does something
when
> > something else happens in the program.
> >
> > Code wise, I have:
> > sub akilltimeout {
> >     while (1) {
> >         # do time checking here
> >         sleep 1;
> >     }
> > }
> >
> > This is executed within another sub by threads, when the program
> > is ready to
> > start it, with:
> > $t = Thread->new(\&akilltimeout);
> >
> > I'm using "Thread" not "threads". What am I doing wrong? Is
> > "threads" better
> > than "Thread", and will it do what I want it to?
> >
> > Many thanks.
> >
> > Dan
> >
>
> Which version of perl are you using? If you are using 5.8 -
> use 'threads' - that is the new (working) threading model!
>
> Your example _should_ then work (with 5.8). You may want to
> put a:
>
>   threads->yeild;
>
> in the loop.
>
> I recommend:
>
> 1) upgrade to 5.8
> 2) read perldoc perlthtut
>
> before using threads.
>
> Aloha => Beau;
>
>



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

Reply via email to