threads package missing is_running
threads package missing is_running
am 02.05.2008 17:08:20 von webmaster
Hi All,
I'm attempting to use the 'threads' module in ActivePerl 5.8.0 build 805.
Everything seems to work until I attempt to shut the process down
gracefully. When I call is_running() the whole thing crashes with the
following output (main thread starts the shutdown after 10 seconds):
Starting Thread Test
This is the main thread (1)
This is the child thread (0)
This is the main thread (2)
This is the main thread (3)
This is the child thread (1)
This is the main thread (4)
This is the main thread (5)
This is the child thread (2)
This is the main thread (6)
This is the main thread (7)
This is the child thread (3)
This is the main thread (8)
This is the main thread (9)
This is the child thread (4)
This is the main thread (10)
Can't locate auto/threads/is_running.al in @INC (@INC contains:
C:/Perl/lib C:/P
erl/site/lib .) at thread_test.pl line 26
A thread exited while 2 other threads were still running.
I'm including the module as follows:
use threads;
use threads::shared;
use strict;
Any idea why it can't find that function?
- Steve
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running
am 02.05.2008 17:36:52 von Brian Raven
webmaster@nanovox.com <> wrote:
> Hi All,
> =
> I'm attempting to use the 'threads' module in ActivePerl 5.8.0 build
> 805. =
> Everything seems to work until I attempt to shut the process down
> gracefully. When I call is_running() the whole thing crashes with
> the following output (main thread starts the shutdown after 10
> seconds): =
> =
> Starting Thread Test
> This is the main thread (1)
> This is the child thread (0)
> This is the main thread (2)
> This is the main thread (3)
> This is the child thread (1)
> This is the main thread (4)
> This is the main thread (5)
> This is the child thread (2)
> This is the main thread (6)
> This is the main thread (7)
> This is the child thread (3)
> This is the main thread (8)
> This is the main thread (9)
> This is the child thread (4)
> This is the main thread (10)
> Can't locate auto/threads/is_running.al in @INC (@INC contains:
> C:/Perl/lib C:/P
> erl/site/lib .) at thread_test.pl line 26 A thread exited while 2
> other threads were still running. =
> =
> I'm including the module as follows:
> =
> use threads;
> use threads::shared;
> use strict;
> =
> Any idea why it can't find that function?
How are you calling it?
A small self contained example script that demonstrates the problem
would help.
Note that your Perl version is pretty old. Perl's threading was not
nearly as mature as it is now (and some would say that it is still not
mature enough for production use). I recommend installing a much later
version.
HTH
-- =
Brian Raven =
==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================
The information contained in this e-mail is confidential and solely for the=
intended addressee(s). Unauthorised reproduction, disclosure, modification=
, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediat=
ely and delete it from your system. The views expressed in this message do =
not necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with=
registration no. 3962327. Registered office address at 25 Bank Street Lon=
don E14 5NQ United Kingdom. =
Atos Euronext Market Solutions SAS - Registered in France with registration=
no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 750=
09 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: threads package missing is_running
am 02.05.2008 17:40:23 von webmaster
Yes, the threads module comes pre-packaged with ActivePerl, and does not
appear to exist according to PPM, so it's not upgradable without upgrading
ActivePerl, which involves me dealing with company red-tape.
The elusive "is_running.al" shouldn't need to exist outside of the module
itself. It's all part of Perl\lib\threads.pm and its associated
lib\auto\threads\ library.
Additionally, I can't seem to get any of the constants from threads to
work. Documentation refers to threads::running and I get a bareword error
when I try to use that.
See documentation at http://perldoc.perl.org/threads.html
>> Hi All,
>>
>> I'm attempting to use the 'threads' module in ActivePerl 5.8.0 build
>> 805.
>> Everything seems to work until I attempt to shut the process down
>> gracefully. When I call is_running() the whole thing crashes with the
>> following output (main thread starts the shutdown after 10 seconds):
>>
>> Starting Thread Test
>> This is the main thread (1)
>> This is the child thread (0)
>> This is the main thread (2)
>> This is the main thread (3)
>> This is the child thread (1)
>> This is the main thread (4)
>> This is the main thread (5)
>> This is the child thread (2)
>> This is the main thread (6)
>> This is the main thread (7)
>> This is the child thread (3)
>> This is the main thread (8)
>> This is the main thread (9)
>> This is the child thread (4)
>> This is the main thread (10)
>> Can't locate auto/threads/is_running.al in @INC (@INC contains:
>> C:/Perl/lib C:/P
>> erl/site/lib .) at thread_test.pl line 26
>> A thread exited while 2 other threads were still running.
>>
>> I'm including the module as follows:
>>
>> use threads;
>> use threads::shared;
>> use strict;
>>
>> Any idea why it can't find that function?
>>
>> - Steve
>>
>
> Have you checked that file actually exists and it's location? Do you
> have the latest versions of the modules installed?
>
>
>
> Lyle
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: threads package missing is_running
am 02.05.2008 17:45:56 von webmaster
webmaster@nanovox.com wrote:
> Hi All,
>
> I'm attempting to use the 'threads' module in ActivePerl 5.8.0 build
> 805. Everything seems to work until I attempt to shut the process down
> gracefully. When I call is_running() the whole thing crashes with the
> following output (main thread starts the shutdown after 10 seconds):
>
> Starting Thread Test
> This is the main thread (1)
> This is the child thread (0)
> This is the main thread (2)
> This is the main thread (3)
> This is the child thread (1)
> This is the main thread (4)
> This is the main thread (5)
> This is the child thread (2)
> This is the main thread (6)
> This is the main thread (7)
> This is the child thread (3)
> This is the main thread (8)
> This is the main thread (9)
> This is the child thread (4)
> This is the main thread (10)
> Can't locate auto/threads/is_running.al in @INC (@INC contains:
> C:/Perl/lib C:/P
> erl/site/lib .) at thread_test.pl line 26
> A thread exited while 2 other threads were still running.
>
> I'm including the module as follows:
>
> use threads;
> use threads::shared;
> use strict;
>
> Any idea why it can't find that function?
>
> - Steve
>
Have you checked that file actually exists and it's location? Do you
have the latest versions of the modules installed?
Lyle
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: threads package missing is_running
am 02.05.2008 17:49:30 von webmaster
webmaster@nanovox.com wrote:
> Yes, the threads module comes pre-packaged with ActivePerl, and does not
> appear to exist according to PPM, so it's not upgradable without upgrading
> ActivePerl, which involves me dealing with company red-tape.
>
Think you'll need to upgrade.
> The elusive "is_running.al" shouldn't need to exist outside of the module
> itself. It's all part of Perl\lib\threads.pm and its associated
> lib\auto\threads\ library.
>
That file still needs exist. auto breaks up the .pm file and creates the
auto files on installing a package. You could try commenting out the
autoloader from Threads.pm but I suggest you upgrade perl. The red tape
will be worth it.
> Additionally, I can't seem to get any of the constants from threads to
> work. Documentation refers to threads::running and I get a bareword error
> when I try to use that.
>
> See documentation at http://perldoc.perl.org/threads.html
>
>
Upgrade perl :)
Lyle
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running
am 02.05.2008 18:05:48 von webmaster
I'd love it if I could just upgrade perl, but corporate bureaucracy sucks
and the new versions need approval for security purposes. I initially
tried it with 5.6.1 with less success, and 5.8.0 seems to be very close
less the is_running issue. All I really need is some way to determine if
the thread is still running even if it's checking if the process id
exists. When it is, I want to SIGUSR1 the thread.
'threads' is a standard module, so I have no clue why it's having amnesia.
The module is found at C:/Perl/lib/threads.pm and not part of the ppm.
Here is a short example of threads I'm testing:
# Test Threads
use threads;
use threads::shared;
use strict;
use vars qw ($counter $thr);
Log ("Starting Thread Test");
$thr =3D threads->create (\&ChildThread, 0, 1);
$counter =3D 0;
while ($counter++ < 10) {
Log ("This is the main thread (".$counter." sec)");
sleep (1);
}
# The following gives an error that is_running.al is missing.
# Tried threads->list (threads::running) to search and compare: gave
bareword error.
# Tried "$thr->is_running" without success: also said is_running.al missing.
while ($thr->is_running()) {
Log ("Killing thread.");
$thr->kill('SIGUSR1');
sleep (4);
}
Log ("Thread killed.");
# Functions
sub Log { my( $Message ) =3D @_; print $Message."\n"; }
sub ChildThread {
my ($counter, $to_screen) =3D @_;
my $count =3D 0;
our $thread_term =3D 0;
$SIG{'SIGUSR1'} =3D sub { Log('Received user1 notice.'); $thread_term =
=3D
1; return 0; };
$SIG{'KILL'} =3D sub { Log('Received kill notice.'); $thread_term =3D 1;
return 0; };
while (!($thread_term)) {
Log ('This is the child thread ('.($count++ * 2).' sec)');
sleep (2);
}
Log ('Thread has ended.');
}
>> Hi All,
>>
>> I'm attempting to use the 'threads' module in ActivePerl 5.8.0 build
>> 805.
>> Everything seems to work until I attempt to shut the process down
>> gracefully. When I call is_running() the whole thing crashes with
>> the following output (main thread starts the shutdown after 10
>> seconds):
>>
>> Starting Thread Test
>> This is the main thread (1)
>> This is the child thread (0)
>> This is the main thread (2)
>> This is the main thread (3)
>> This is the child thread (1)
>> This is the main thread (4)
>> This is the main thread (5)
>> This is the child thread (2)
>> This is the main thread (6)
>> This is the main thread (7)
>> This is the child thread (3)
>> This is the main thread (8)
>> This is the main thread (9)
>> This is the child thread (4)
>> This is the main thread (10)
>> Can't locate auto/threads/is_running.al in @INC (@INC contains:
>> C:/Perl/lib C:/P
>> erl/site/lib .) at thread_test.pl line 26 A thread exited while 2
>> other threads were still running.
>>
>> I'm including the module as follows:
>>
>> use threads;
>> use threads::shared;
>> use strict;
>>
>> Any idea why it can't find that function?
>
> How are you calling it?
>
> A small self contained example script that demonstrates the problem
> would help.
>
> Note that your Perl version is pretty old. Perl's threading was not
> nearly as mature as it is now (and some would say that it is still not
> mature enough for production use). I recommend installing a much later
> version.
>
> HTH
>
> --
> Brian Raven
>
> ==================== =====
=================3D
> Atos Euronext Market Solutions Disclaimer
> ==================== =====
=================3D
>
> The information contained in this e-mail is confidential and solely for
> the intended addressee(s). Unauthorised reproduction, disclosure,
> modification, and/or distribution of this email may be unlawful.
> If you have received this email in error, please notify the sender
> immediately and delete it from your system. The views expressed in this
> message do not necessarily reflect those of Atos Euronext Market
> Solutions.
>
> Atos Euronext Market Solutions Limited - Registered in England & Wales
> with registration no. 3962327. Registered office address at 25 Bank
> Street London E14 5NQ United Kingdom.
> Atos Euronext Market Solutions SAS - Registered in France with
> registration no. 425 100 294. Registered office address at 6/8 Boulevard
> Haussmann 75009 Paris France.
>
> L'information contenue dans cet e-mail est confidentielle et uniquement
> destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
> Toute copie, publication ou diffusion de cet email est interdite. Si cet
> e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir
> l'expediteur immediatement et d'effacer le e-mail et annexes jointes de
> votre systeme. Le contenu de ce message electronique ne represente pas
> necessairement la position ou le point de vue d'Atos Euronext Market
> Solutions.
> Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais,
> enregistr=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge so=
cial se
> situe 25 Bank Street E14 5NQ Londres Royaume Uni.
>
> Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e,
> enregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9r=
o 425 100
> 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Haussmann
> 75009 Paris France.
> ==================== =====
=================3D
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running
am 02.05.2008 18:50:05 von Brian Raven
webmaster@nanovox.com wrote:
> I'd love it if I could just upgrade perl, but corporate bureaucracy
> sucks and the new versions need approval for security purposes. I
> initially tried it with 5.6.1 with less success, and 5.8.0 seems to
> be very close less the is_running issue. All I really need is some
> way to determine if the thread is still running even if it's checking
> if the process id exists. When it is, I want to SIGUSR1 the thread. =
> =
> 'threads' is a standard module, so I have no clue why it's having
> amnesia. The module is found at C:/Perl/lib/threads.pm and not part
> of the ppm. =
> =
> Here is a short example of threads I'm testing:
> =
>
> # Test Threads
> use threads;
> use threads::shared;
> use strict;
> use vars qw ($counter $thr);
> =
> Log ("Starting Thread Test");
> $thr =3D threads->create (\&ChildThread, 0, 1);
> =
> $counter =3D 0;
> while ($counter++ < 10) {
> Log ("This is the main thread (".$counter." sec)");
> sleep (1);
> }
> =
> # The following gives an error that is_running.al is missing.
> # Tried threads->list (threads::running) to search and compare: gave
> bareword error. # Tried "$thr->is_running" without success: also said
> is_running.al missing. =
> while ($thr->is_running()) {
> Log ("Killing thread.");
> $thr->kill('SIGUSR1');
> sleep (4);
> }
> =
> Log ("Thread killed.");
> =
> # Functions
> =
> sub Log { my( $Message ) =3D @_; print $Message."\n"; }
> =
> sub ChildThread {
> my ($counter, $to_screen) =3D @_;
> my $count =3D 0;
> our $thread_term =3D 0;
> $SIG{'SIGUSR1'} =3D sub { Log('Received user1 notice.');
> $thread_term =3D 1; return 0; }; $SIG{'KILL'} =3D sub { Log('Received
> kill notice.'); $thread_term =3D 1; return 0; }; =
> =
> while (!($thread_term)) {
> Log ('This is the child thread ('.($count++ * 2).' sec)');
> sleep (2);
> }
> Log ('Thread has ended.');
> }
>
It occurs to me that you might be using the documentation for a later
version of Perl than you are using. The function is_running is
documented in 5.10.0, but not in an older version (5.8.5) that I have.
Neither is the kill function come to that.
Try something like the following, which seems to work in my older
version.
use strict;
use warnings;
use threads;
use threads::shared;
my $thread_term : shared =3D 0;
Log ("Starting Thread Test");
my $thr =3D threads->create (\&ChildThread, 0, 1);
my $counter =3D 0;
while ($counter++ < 10) {
Log ("This is the main thread (".$counter." sec)");
sleep (1);
}
terminate(1);
$thr->join();
Log ("Thread killed.");
# Functions
sub Log { my( $Message ) =3D @_; print $Message."\n"; }
sub ChildThread {
my ($counter, $to_screen) =3D @_;
my $count =3D 0;
while (!terminate()) {
Log ('This is the child thread ('.($count++ * 2).' sec)');
sleep (2);
}
Log ('Thread has ended.');
}
sub terminate {
lock $thread_term;
$thread_term =3D $_[0] if defined $_[0];
return $thread_term;
}
HTH
-- =
Brian Raven =
==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================
The information contained in this e-mail is confidential and solely for the=
intended addressee(s). Unauthorised reproduction, disclosure, modification=
, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediat=
ely and delete it from your system. The views expressed in this message do =
not necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with=
registration no. 3962327. Registered office address at 25 Bank Street Lon=
don E14 5NQ United Kingdom. =
Atos Euronext Market Solutions SAS - Registered in France with registration=
no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 750=
09 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running
am 02.05.2008 18:51:24 von Andy_Bach
>
# The following gives an error that is_running.al is missing.
# Tried threads->list (threads::running) to search and compare: gave
# bareword error.
Tried the code on linux, got the same error so activeperl is off the hook.
"list" should be:
$thr->list()
The perldocs show no is_running method, nor a kill() method, for threads.
I think
$thr->kill('SIGUSR1');
is a mix of info here, you mean to send a signal to $thr but
while ($thr->list() ) {
isn't ... er quite right? Seems you need join/detach and to keep the
thread ids somewhere
a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932
"When angry, count to four; when very angry, swear."
Mark Twain
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running
am 02.05.2008 19:00:30 von Andy_Bach
Brian:
Starting Thread Test
This is the child thread (0 sec)
This is the main thread (1 sec)
This is the main thread (2 sec)
This is the child thread (2 sec)
This is the main thread (3 sec)
This is the main thread (4 sec)
This is the child thread (4 sec)
This is the main thread (5 sec)
This is the main thread (6 sec)
This is the child thread (6 sec)
This is the main thread (7 sec)
This is the main thread (8 sec)
This is the child thread (8 sec)
This is the main thread (9 sec)
This is the main thread (10 sec)
This is the child thread (10 sec)
Thread has ended.
Thread killed.
was that what was expected? I was thinking there'd be a count down or such
as each thread died and *then* the main thread dies.
a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932
"When angry, count to four; when very angry, swear."
Mark Twain
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running (solvedish)
am 02.05.2008 21:19:24 von webmaster
I thought about the locking approach, but this will all eventually be
wrapped into a Windows services tool that will shutdown the service
gracefully.
The way services work, the process needs to ping the service control
manager once in a while when it is still running. So, if a thread didn't
shutdown after a join() in x number of seconds, Windows would assume the
program is not responding. And who knows how long a worker thread will
spend on one task before saying hello again. This is essentially how they
will talk:
Worker Threads <-> Master Thread / Services Callback Thread <-> Windows
Services
I can say I found something similar to your idea that works nicely. =
Thanks to the 'async' command, I can use a shared variable and adjust that
variable after it asynchronously joins the threads. Yes, very much in the
realm of hacks and bad ideas, but it works. With the verbage of this
thing, it really sounds like nonsense spawning threads from the master and
joining them to another child.
# Test Threads
use threads;
use threads::shared;
use Win32;
use strict;
use vars qw ($counter $thr $thread $threads);
my $thread_shutdown : shared;
Log ("Starting Thread Test");
$thr =3D threads->create (\&ChildThread, 0);
$counter =3D 0;
while ($counter++ < 60) {
sleep (1);
Log ('This is the main thread speaking: '.localtime(time()));
}
# Signal shutdown state
$thread_shutdown =3D 1;
# Asynchronously join threads.
$threads =3D threads->list();
async {
my $result;
foreach $thread ($threads) {
$result =3D $thread->join ();
Log ("Result for thread ".$thread->tid.": ".$result);
}
# Signal final shutdown state
$thread_shutdown =3D 2;
};
# Await shutdown state change
while ($thread_shutdown < 2) {
Log ("Awaiting thread death.");
sleep (10);
}
Log ("Application is ended.");
# Functions
sub Log { my( $Message ) =3D @_; print $Message."\n"; }
sub ChildThread {
my ($counter) =3D @_;
while (!$thread_shutdown) {
Log ('This is the child thread speaking: '.localtime(time()));
Win32::Sleep ((rand(12)+1) * 500);
}
Log ('Thread has ended.');
return 10;
}
>> I'd love it if I could just upgrade perl, but corporate bureaucracy
>> sucks and the new versions need approval for security purposes. I
>> initially tried it with 5.6.1 with less success, and 5.8.0 seems to
>> be very close less the is_running issue. All I really need is some
>> way to determine if the thread is still running even if it's checking
>> if the process id exists. When it is, I want to SIGUSR1 the thread.
>>
>> 'threads' is a standard module, so I have no clue why it's having
>> amnesia. The module is found at C:/Perl/lib/threads.pm and not part
>> of the ppm.
>>
>> Here is a short example of threads I'm testing:
>>
>>
>> # Test Threads
>> use threads;
>> use threads::shared;
>> use strict;
>> use vars qw ($counter $thr);
>>
>> Log ("Starting Thread Test");
>> $thr =3D threads->create (\&ChildThread, 0, 1);
>>
>> $counter =3D 0;
>> while ($counter++ < 10) {
>> Log ("This is the main thread (".$counter." sec)");
>> sleep (1);
>> }
>>
>> # The following gives an error that is_running.al is missing.
>> # Tried threads->list (threads::running) to search and compare: gave
>> bareword error. # Tried "$thr->is_running" without success: also said
>> is_running.al missing.
>> while ($thr->is_running()) {
>> Log ("Killing thread.");
>> $thr->kill('SIGUSR1');
>> sleep (4);
>> }
>>
>> Log ("Thread killed.");
>>
>> # Functions
>>
>> sub Log { my( $Message ) =3D @_; print $Message."\n"; }
>>
>> sub ChildThread {
>> my ($counter, $to_screen) =3D @_;
>> my $count =3D 0;
>> our $thread_term =3D 0;
>> $SIG{'SIGUSR1'} =3D sub { Log('Received user1 notice.');
>> $thread_term =3D 1; return 0; }; $SIG{'KILL'} =3D sub { Log('Received
>> kill notice.'); $thread_term =3D 1; return 0; };
>>
>> while (!($thread_term)) {
>> Log ('This is the child thread ('.($count++ * 2).' sec)');
>> sleep (2);
>> }
>> Log ('Thread has ended.');
>> }
>>
>
> It occurs to me that you might be using the documentation for a later
> version of Perl than you are using. The function is_running is
> documented in 5.10.0, but not in an older version (5.8.5) that I have.
> Neither is the kill function come to that.
>
> Try something like the following, which seems to work in my older
> version.
>
> use strict;
> use warnings;
> use threads;
> use threads::shared;
>
> my $thread_term : shared =3D 0;
>
> Log ("Starting Thread Test");
> my $thr =3D threads->create (\&ChildThread, 0, 1);
>
> my $counter =3D 0;
> while ($counter++ < 10) {
> Log ("This is the main thread (".$counter." sec)");
> sleep (1);
> }
>
> terminate(1);
> $thr->join();
> Log ("Thread killed.");
>
> # Functions
>
> sub Log { my( $Message ) =3D @_; print $Message."\n"; }
>
> sub ChildThread {
> my ($counter, $to_screen) =3D @_;
> my $count =3D 0;
>
> while (!terminate()) {
> Log ('This is the child thread ('.($count++ * 2).' sec)');
> sleep (2);
> }
> Log ('Thread has ended.');
> }
>
> sub terminate {
> lock $thread_term;
> $thread_term =3D $_[0] if defined $_[0];
> return $thread_term;
> }
>
> HTH
>
> --
> Brian Raven
>
> ==================== =====
=================3D
> Atos Euronext Market Solutions Disclaimer
> ==================== =====
=================3D
>
> The information contained in this e-mail is confidential and solely for
> the intended addressee(s). Unauthorised reproduction, disclosure,
> modification, and/or distribution of this email may be unlawful.
> If you have received this email in error, please notify the sender
> immediately and delete it from your system. The views expressed in this
> message do not necessarily reflect those of Atos Euronext Market
> Solutions.
>
> Atos Euronext Market Solutions Limited - Registered in England & Wales
> with registration no. 3962327. Registered office address at 25 Bank
> Street London E14 5NQ United Kingdom.
> Atos Euronext Market Solutions SAS - Registered in France with
> registration no. 425 100 294. Registered office address at 6/8 Boulevard
> Haussmann 75009 Paris France.
>
> L'information contenue dans cet e-mail est confidentielle et uniquement
> destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
> Toute copie, publication ou diffusion de cet email est interdite. Si cet
> e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir
> l'expediteur immediatement et d'effacer le e-mail et annexes jointes de
> votre systeme. Le contenu de ce message electronique ne represente pas
> necessairement la position ou le point de vue d'Atos Euronext Market
> Solutions.
> Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais,
> enregistr=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge so=
cial se
> situe 25 Bank Street E14 5NQ Londres Royaume Uni.
>
> Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e,
> enregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9r=
o 425 100
> 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Haussmann
> 75009 Paris France.
> ==================== =====
=================3D
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running
am 06.05.2008 11:19:45 von Brian Raven
Andy_Bach@wiwb.uscourts.gov <> wrote:
> Brian:
> Starting Thread Test
> This is the child thread (0 sec)
> This is the main thread (1 sec)
> This is the main thread (2 sec)
> This is the child thread (2 sec)
> This is the main thread (3 sec)
> This is the main thread (4 sec)
> This is the child thread (4 sec)
> This is the main thread (5 sec)
> This is the main thread (6 sec)
> This is the child thread (6 sec)
> This is the main thread (7 sec)
> This is the main thread (8 sec)
> This is the child thread (8 sec)
> This is the main thread (9 sec)
> This is the main thread (10 sec)
> This is the child thread (10 sec)
> Thread has ended.
> Thread killed.
> =
> was that what was expected? I was thinking there'd be a count down or
> such as each thread died and *then* the main thread dies. =
That's pretty much what I would expect. My code was based on the OP's,
in which there was only one child, and the counter in both main and
child thread increment rather than decrement.
HTH
-- =
Brian Raven =
==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================
The information contained in this e-mail is confidential and solely for the=
intended addressee(s). Unauthorised reproduction, disclosure, modification=
, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediat=
ely and delete it from your system. The views expressed in this message do =
not necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with=
registration no. 3962327. Registered office address at 25 Bank Street Lon=
don E14 5NQ United Kingdom. =
Atos Euronext Market Solutions SAS - Registered in France with registration=
no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 750=
09 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running (solvedish)
am 06.05.2008 12:37:14 von Brian Raven
webmaster@nanovox.com wrote:
> I thought about the locking approach, but this will all eventually be
> wrapped into a Windows services tool that will shutdown the service
> gracefully. =
I don't see how that removes the need for locking when changing shared
variables? =
> =
> The way services work, the process needs to ping the service control
> manager once in a while when it is still running. So, if a thread
> didn't shutdown after a join() in x number of seconds, Windows would
> assume the program is not responding. And who knows how long a
> worker thread will spend on one task before saying hello again. This
> is essentially how they will talk: =
> =
> Worker Threads <-> Master Thread / Services Callback Thread <->
> Windows Services =
Sorry, but I don't really follow that.
> =
> I can say I found something similar to your idea that works nicely.
> Thanks to the 'async' command, I can use a shared variable and adjust
> that variable after it asynchronously joins the threads. Yes, very
> much in the realm of hacks and bad ideas, but it works. With the
> verbage of this thing, it really sounds like nonsense spawning
> threads from the master and joining them to another child. =
I'm not sure that it does work (see comments in code),except by
coincidence. It certainly doesn't work in later versions of Perl.
> =
>
> # Test Threads
> =
> use threads;
> use threads::shared;
> use Win32;
> use strict;
> =
> use vars qw ($counter $thr $thread $threads);
Prefer declare variables lexically (i.e. my ...), unless you actually
need to do otherwise.
> my $thread_shutdown :
> shared; =
> =
> Log ("Starting Thread Test");
> =
> $thr =3D threads->create (\&ChildThread, 0);
> =
> $counter =3D 0;
> while ($counter++ < 60) {
> sleep (1);
> Log ('This is the main thread speaking: '.localtime(time())); }
> =
> # Signal shutdown state
> $thread_shutdown =3D 1;
> =
> # Asynchronously join threads.
> $threads =3D threads->list();
Note that $threads contains a single thread object ...
> async {
> my $result;
> foreach $thread ($threads) {
.... this will therefor be a problem if you have more than one thread.
> $result =3D $thread->join ();
> Log ("Result for thread ".$thread->tid.": ".$result);
> }
> # Signal final shutdown state
> $thread_shutdown =3D 2;
> };
Also you don't join the async thread. Older versions of Perl might not
complain about that, but later ones will.
> =
> # Await shutdown state change
> while ($thread_shutdown < 2) {
> Log ("Awaiting thread death.");
> sleep (10);
> }
> =
> Log ("Application is ended.");
> =
> # Functions
> =
> sub Log { my( $Message ) =3D @_; print $Message."\n"; }
> =
> sub ChildThread {
> my ($counter) =3D @_;
> =
> while (!$thread_shutdown) {
> Log ('This is the child thread speaking: '.localtime(time()));
> Win32::Sleep ((rand(12)+1) * 500);
> }
> Log ('Thread has ended.');
> return 10;
> }
>
I don't see what creating a separate thread to do wait for your
child/worker threads to terminate, then waiting for it to terminate
gives you. It seems to be the very opposite of async.
HTH
-- =
Brian Raven =
==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================
The information contained in this e-mail is confidential and solely for the=
intended addressee(s). Unauthorised reproduction, disclosure, modification=
, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediat=
ely and delete it from your system. The views expressed in this message do =
not necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with=
registration no. 3962327. Registered office address at 25 Bank Street Lon=
don E14 5NQ United Kingdom. =
Atos Euronext Market Solutions SAS - Registered in France with registration=
no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 750=
09 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: threads package missing is_running (solvedish)
am 06.05.2008 13:22:53 von Bill Luebkert
Brian Raven wrote:
>
>> use vars qw ($counter $thr $thread $threads);
>
> Prefer declare variables lexically (i.e. my ...), unless you actually
> need to do otherwise.
Me too.
>> # Asynchronously join threads.
>> $threads = threads->list();
>
> Note that $threads contains a single thread object ...
Actually it doesn't - it contains the number of non-joined, non-detached
thread objects.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: threads package missing is_running (solvedish)
am 06.05.2008 13:41:56 von Brian Raven
Bill Luebkert <> wrote:
> Brian Raven wrote:
>> =
>>> use vars qw ($counter $thr $thread $threads);
>> =
>> Prefer declare variables lexically (i.e. my ...), unless you actually
>> need to do otherwise.
> =
> Me too.
> =
>>> # Asynchronously join threads.
>>> $threads =3D threads->list();
>> =
>> Note that $threads contains a single thread object ...
> =
> Actually it doesn't - it contains the number of non-joined,
> non-detached thread objects.
True, but only for more recent versions of Perl (certainly 5.10.0). In
older versions, certainly in 5.8.5 and probably the OPs which is older,
it returns a list. And the result of evaluating a list in a scalar
context is the last entry.
All of which, IMHO, adds weight to the argument that the OP should
upgrade to a later version of Perl if he wants to use threads.
HTH
-- =
Brian Raven =
==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================
The information contained in this e-mail is confidential and solely for the=
intended addressee(s). Unauthorised reproduction, disclosure, modification=
, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediat=
ely and delete it from your system. The views expressed in this message do =
not necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with=
registration no. 3962327. Registered office address at 25 Bank Street Lon=
don E14 5NQ United Kingdom. =
Atos Euronext Market Solutions SAS - Registered in France with registration=
no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 750=
09 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs