perl on windows stuck on calling for usleep from another module

118 Views Asked by At

I'm using the following perl code on windows environment:

use Time::HiRes qw(usleep);

    #(some code here)

$self->{GLOBAL_OBJ}->xsleep($delay) if($delay);


sub xsleep {    
    my $seconds = shift;
    #print "will sleep:$seconds seconds\n";
    $seconds = $seconds * 1000000;
    usleep($seconds);
    #print "slept:$seconds micro seconds\n";

    return 0;
}

When I call xsleep like that (from another module) the system is stuck and I can only stop it by ctrl+c, however when I call it from the current module it works fine.

Can anyone tell me why this is and how can I fix it? Thanks

1

There are 1 best solutions below

0
On

xsleep is being called as a method, which means the invocant (the result of the left side of ->) is passed as the first argument. This is currently ending up in $seconds. References numify to their address, so you get an extremely large numbers in $seconds. For example,

$ perl -e'CORE::say(0+{})'
9304720

Either adjust xsleep so it can be called as a method,

$self->{GLOBAL_OBJ}->xsleep($delay) if $delay;

sub xsleep {    
    my $self    = shift;
    my $seconds = shift;
    ...
}

or call xsleep as a sub

The::Package::xsleep($delay) if $delay;

sub xsleep {    
    my $seconds = shift;
    ...
}