in reply to Threads and ALARM() - There is a solution or workaround?

Alarm uses signals. Signals are sent to processes, not threads. Also, it means you can only have one alarm in effect at a time. If you want to use alarm, you can't use threads.

In your case, when one thread exits, it resets the signal handler for everyone, making the alarm fatal. Your shell reports that your program died from the alarm signal by printing "Alarm clock".

$ perl -e'alarm(1); sleep' Alarm clock

Replies are listed 'Best First'.
Re^2: Threads and ALARM() - There is a solution or workaround?
by perlmonks12 (Novice) on May 10, 2010 at 17:11 UTC
    Thanks for answer. But there is no solution? I need to have a slow program? It's kind of disappointing. There is another option instead of alarm() to timeout my call to Net::SOCKS? Some workaround as select() in C? Maybe threads queue? I'm very new to perl, but I can't believe that a simple task like that is unsolved. Thank you

      In general, you could avoid alarm by using select with a timeout, or you could avoid using threads by forking instead.

      The Net::SOCKS object might by a selectable file handle.