W
Walter Roberson
I wonder if someone could give me some hints how to enable
ithread support conditionally at run-time ?
I have written a multi-threaded firewall log analysis program that
calls upon a series of utility modules that I've written. Shared
variables are involved (and Queues, but the Queues don't seem to be a
problem at the moment.) I described some of the effort and lessons in a
previous topic in this newsgroup.
As the program is slower than I'd prefer, I attempted to profile with
-dProf . That failed miserably on any module for which I had
use threads::shared complaining that,
panic: Devel:Prof inconsistent subroutine return at /usr/freeware/lib/perl5/5.8.2/irix-n32-thread-multi/threads/shared.pm line 17.
According to the Devel:Prof documentation, this is a known failure
mode for certain kinds of returns from routines (involving labels.)
I rejigged my modules to do require's instead of use's, and built in
the appropriate run-time logic to know whether to bother to place
lock() and share() calls. In my main code, I placed the appropriate
logic to know to proceed linearily instead of multi-threaded depending
on a run-time option. With appropriate placement of () to delimit
function calls [instead relying on prototypes being available],
and a few other misc. tweaks, I was able to make Devel:Prof happy.
(Looks like massive numbers of split() are my slow point still.)
And in the process I improved the utility modules so they should now
work even without threads configured. A nuisance, but not a wasted effort.
And everything seemed fine until I went to switch back to threaded mode.
When I stopped giving my new run-time option, one of the modules
started complaining that I need to use threads before I
use threads::shared . Some experimentation showed I had to change my
require threads; in my main routine to use threads; instead,
to stop the message... or at least that was the easiest way I could find.
[NB: threads::shared does some magic to force you to include them
in the right order.] But with the 'use' instead of 'require',
Devel:Prof breaks again...
So, at the moment I seem to be stuck. If I use a 'require' then
threads::shared knows that threads weren't invoked at compile time and
shared threads don't work. But if I use a 'use' then Devel:Prof can't
monitor the program.
It's all down to a single statement, but a statement that seemingly
has to go in at compile time rather than at run-time.
Is it fair game to examine @ARGV in a BEGIN block?
Or am I going to have to use some hack such as requiring the
program be invoked via perl -Mthreads to supply the compile-time
context for threads when I want threads used?
Uggh, just realized I could pull a trick such as exec()ing
itself as perl -Mthreads Blech!
ithread support conditionally at run-time ?
I have written a multi-threaded firewall log analysis program that
calls upon a series of utility modules that I've written. Shared
variables are involved (and Queues, but the Queues don't seem to be a
problem at the moment.) I described some of the effort and lessons in a
previous topic in this newsgroup.
As the program is slower than I'd prefer, I attempted to profile with
-dProf . That failed miserably on any module for which I had
use threads::shared complaining that,
panic: Devel:Prof inconsistent subroutine return at /usr/freeware/lib/perl5/5.8.2/irix-n32-thread-multi/threads/shared.pm line 17.
According to the Devel:Prof documentation, this is a known failure
mode for certain kinds of returns from routines (involving labels.)
I rejigged my modules to do require's instead of use's, and built in
the appropriate run-time logic to know whether to bother to place
lock() and share() calls. In my main code, I placed the appropriate
logic to know to proceed linearily instead of multi-threaded depending
on a run-time option. With appropriate placement of () to delimit
function calls [instead relying on prototypes being available],
and a few other misc. tweaks, I was able to make Devel:Prof happy.
(Looks like massive numbers of split() are my slow point still.)
And in the process I improved the utility modules so they should now
work even without threads configured. A nuisance, but not a wasted effort.
And everything seemed fine until I went to switch back to threaded mode.
When I stopped giving my new run-time option, one of the modules
started complaining that I need to use threads before I
use threads::shared . Some experimentation showed I had to change my
require threads; in my main routine to use threads; instead,
to stop the message... or at least that was the easiest way I could find.
[NB: threads::shared does some magic to force you to include them
in the right order.] But with the 'use' instead of 'require',
Devel:Prof breaks again...
So, at the moment I seem to be stuck. If I use a 'require' then
threads::shared knows that threads weren't invoked at compile time and
shared threads don't work. But if I use a 'use' then Devel:Prof can't
monitor the program.
It's all down to a single statement, but a statement that seemingly
has to go in at compile time rather than at run-time.
Is it fair game to examine @ARGV in a BEGIN block?
Or am I going to have to use some hack such as requiring the
program be invoked via perl -Mthreads to supply the compile-time
context for threads when I want threads used?
Uggh, just realized I could pull a trick such as exec()ing
itself as perl -Mthreads Blech!