Looks like times of old good alarm() call are over, so how to interrupt blocking read()'s and write()'s made from perl thread (using that brand new 'threads' module) assuming the code making those blocking calls cannot be changed? Actual problem is stucking communication with Modbus device so I've created a simple testcase not to dip you into RS-485 hell:
use threads;
use IO::Handle;
threads->create(sub {
$io = IO::Handle->new_from_fd(fileno(STDIN), 'r') or die;
$br = read $io, $buf, 100;
warn "read: $br";
});
while(1) {threads->yield()};
Here, warn() is never executed unless you hit Ctrl-D on keyboard. Is there any simple solution to timeout that read() call?