Assistance with threading ...thread not returning

C

c_campise

Hello all-

I have a 'simple' application that creates a thread that calls an
external Windows program that runs for about 5 minutes or so. The
problem is the routine that creates this thread is never returned
control after the join() has been called when the thread terminates.

Sample Code :

use threads;
$|++; # autoflush enabled

print "Calling GenerateThread()\n";
GenerateThread();
print "Exited GenerateThread()\n";
exit(1)


sub GenerateThread()
{
my $thread1 = threads->create(\&ExecuteThread);
my $val1 = $thread1->join;
print "DONE with ExecuteThread()\n";
}

sub ExecuteThread()
{
# sit and wait for command to finish....
$szResult = `MyWindowsCommandLineProgram`;

print "MyWindowsCommandLineProgram has COMPLETED\n";
}


----- actual program output ---------

Calling GenerateThread()
MyWindowsCommandLineProgram has COMPLETED
DONE with ExecuteThread()

------end actual output -------------

What I never see is control returned to where GenerateThread() was
called. I expected to see :

----- expected program output ---------

Calling GenerateThread()
MyWindowsCommandLineProgram has COMPLETED
DONE with ExecuteThread()
Exited GenerateThread() <<--- ????

-------end expected ouput -------------

Any ideas what I'm doing wrong?

Thanks in advance!

Chris
 
A

A. Sinan Unur

(e-mail address removed) wrote in @l41g2000cwc.googlegroups.com:
I have a 'simple' application that creates a thread that calls an
external Windows program that runs for about 5 minutes or so. The
problem is the routine that creates this thread is never returned
control after the join() has been called when the thread terminates.

Sample Code :

use strict;
use warnings;

missing. Please do read the posting guidelines for this group. They
contain valuable information on how to help others help you.
use threads;
$|++; # autoflush enabled

This is better written as

$| = 1;
print "Calling GenerateThread()\n";
GenerateThread();
print "Exited GenerateThread()\n";
exit(1)

Please post real code. This code contains a syntax error, which means
this is not the code that you ran.
sub GenerateThread()

Why the empty prototype?
{
my $thread1 = threads->create(\&ExecuteThread);
my $val1 = $thread1->join;
print "DONE with ExecuteThread()\n";
}

sub ExecuteThread()

Why the empty prototype?
{
# sit and wait for command to finish....
$szResult = `MyWindowsCommandLineProgram`;

Hungarian notation. Yuck!
print "MyWindowsCommandLineProgram has COMPLETED\n";
}
Any ideas what I'm doing wrong?

You have not read the posting guidelines.

You did not put together a short script that still exhibits the problem.

After fixing the errors that would have been obvious had you actually
run this script before posting, here is what we have (on Windows XPP-
SP2, ActiveState Perl):
use strict;
use warnings;

use threads;
$| = 1;

print "Calling GenerateThread()\n";
GenerateThread();
print "Exited GenerateThread()\n";
exit 1;

sub GenerateThread {
my $thread1 = threads->create(\&ExecuteThread);
my $val1 = $thread1->join;
print "DONE with ExecuteThread()\n";
}

sub ExecuteThread {
my $output = `ls`;
print "MyWindowsCommandLineProgram has COMPLETED\n";
}

__END__

D:\Home\asu1\UseNet\clpmisc> t
Calling GenerateThread()
MyWindowsCommandLineProgram has COMPLETED
DONE with ExecuteThread()
Exited GenerateThread()
 

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

Members online

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top