On Mon, 3 Nov 2003, Steve Schein wrote:
> What is the current best practice for killing a single thread with
> ithreads?
In this case, I think alteration of program logic is well-suited, esp. since
the thread's loop is already I/O driven. This:
while (defined $udp->read($buf, 8192)) { # Assuming IO::Socket obj.
...
}
becomes something like:
pipe(R, W); # pipe to control processing thread
# UDP processing thread
async {
close W; # don't need it, must close it.
while (1) {
for my $fh (IO::Select->new($udp, \*R)->can_read) {
if ($fh == \*R) {
$udp->close;
return; # all done
}
handle_new_data($udp);
}
}
};
# back to main thread
close(R); # don't need it.
To get the processing thread to quit, close W. can_read() will notice and
return the read-end of the pipe.
Alternatively, you could send yourself a special message over $udp (e.g.,
print {$udp} "QUIT!\n";), but that's not without security considerations, of
course.
Regards,
Mike
--
Michael J. Pomraning
[EMAIL PROTECTED]
http://pilcrow.madison.wi.us