In essence, if I'm hearing you correctly, you're saying that what I am trying to achieve is not possible.
Not all all; it just needs to be done differently. Off the top my head:
Use two perl-level threads: the first is your main program, the second is created with threads->new(...). The main thread does whatever normal activity you want to run; the second runs a loop which calls an XS function which blocks waiting for an interrupt:
use threads;
# interrupt thread
sub handler {
while (1) {
XS_wait_for_interrupt();
print "got interrupt\n";
}
}
threads->new(\&handler)->detach();
# main thread
my $continue = 1;
$SIG{INT} = sub { $continue = 0; };
while ($continue){
...do_work...;
}
How the XS function waits for and wakes up when an interrupt is received depends on the details of how interrupts are implemented on the rPI, about which I no nothing. But maybe have something set and release a mutex, and have XS_wait_for_interrupt() block on the mutex.
If the interrupt perl thread needs to interact with the main thread in some way, then that depends a lot on how they should interact. For example, using threads::shared to pass shared data beteen the threads. Or if the main thread's role is mainly to do tasks based on events, then maybe use one of the various event modules available on CPAN (about which I know very little), where the interrupt is one of the events the main thread can handle.
Dave.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|