threads, Sys::SigAction, alarm, timeout


L

LovingFox

I've got some kind of problem using threads module with Sys::SigAction
module. Look to this too examples:

1. The first (function 't' w/o threads) works good as I need:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use Sys::SigAction qw( set_sig_handler );
t();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2); # here is some usefull code instead 'sleep'
alarm(0);
};
print "end '[email protected]'\n";
}
-------------------------------------------------------------------------

2. The second (function 't' through threads) prints error I cannot
understand:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use threads;
use Sys::SigAction qw( set_sig_handler timeout_call );
threads->new( \&t )->join();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2);
alarm(0);
};
print "end '[email protected]'\n";
}
 
Ad

Advertisements

Z

zentara

I've got some kind of problem using threads module with Sys::SigAction
module. Look to this too examples:

1. The first (function 't' w/o threads) works good as I need:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use Sys::SigAction qw( set_sig_handler );
t();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2); # here is some usefull code instead 'sleep'
alarm(0);
};
print "end '[email protected]'\n";
}
-------------------------------------------------------------------------

2. The second (function 't' through threads) prints error I cannot
understand:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use threads;
use Sys::SigAction qw( set_sig_handler timeout_call );
threads->new( \&t )->join();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2);
alarm(0);
};
print "end '[email protected]'\n";
}
-------------------------------------------------------------------------
This code print this:
Signal SIGALRM received, but no signal handler set.

How it can be overcome?

I don't know about how Sys::Sigaction works, but threads and ALARM
and/or signals don't work with threads. The parent thread receives all
signals, so using them in threads is useless unless you have the parent
handle them.

zentara
 
M

Martijn Lievaart

I don't know about how Sys::Sigaction works, but threads and ALARM
and/or signals don't work with threads. The parent thread receives all
signals, so using them in threads is useless unless you have the parent
handle them.

zentara

from perlthrtut:

] Similarly, mixing signals and threads should not be attempted.
] Implementations are platform-dependent, and even the POSIX semantics
] may not be what you expect (and Perl doesn’t even give you the full
] POSIX API).

So I would not even count on the main thread receiving all signals. Or am
I missing something here?

M4
 
L

LovingFox

I don't know about how Sys::Sigaction works, but threads and ALARM
and/or signals don't work with threads. The parent thread receives all
signals, so using them in threads is useless unless you have the parent
handle them.

from perlthrtut:

] Similarly, mixing signals and threads should not be attempted.
] Implementations are platform-dependent, and even the POSIX semantics
] may not be what you expect (and Perl doesn't even give you the full
] POSIX API).

So I would not even count on the main thread receiving all signals. Or am
I missing something here?

M4

Hmmm... So anybody know how to create timeout catcher for some code in
thread script like I wrote? Such simple example is written here
http://search.cpan.org/~lbaxter/Sys-SigAction-0.10/dbd-oracle-timeout.POD
and I need to use it in code with threads.
 
Ad

Advertisements

L

lincoln.a.baxter

from perlthrtut:
] Similarly, mixing signals and threads should not be attempted.
] Implementations are platform-dependent, and even the POSIX semantics
] may not be what you expect (and Perl doesn't even give you the full
] POSIX API).
So I would not even count on the main thread receiving all signals. Or am
I missing something here?

Hmmm... So anybody know how to create timeout catcher for some code in
thread script like I wrote? Such simple example is written herehttp://search.cpan.org/~lbaxter/Sys-SigAction-0.10/dbd-oracle-timeout...
and I need to use it in code with threads.

I am the author of the sys-sigaction module. Referenced here. I have
privately corresponded with a person I think is the original poster of
this thread. I believe Martijn Lievaart in the post above has nailed
it with his quote from the from perlthrtut:
] Similarly, mixing signals and threads should not be attempted.
] Implementations are platform-dependent, and even the POSIX semantics
] may not be what you expect (and Perl doesn't even give you the full
] POSIX API).

Until perl threads (and the POSIX sigaction API) support this, there
is very little that I think I can do with sys-sigaction to support
it. I have offered to produce a documentation update to sys-sigaction
calling this out, perhaps to at least warn others to avoid trying to
do this. I think one is stuck with not using threads if you wants to
use the technique referenced in sys-sigaction for timing out hung
oracle connection attempts. This post should close this topic with
respect to sys-sigaction, for now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top