Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Simple Thread question
Hi Thread Guru's,
I'm just reading up on Perl threads for the first time from
http://perldoc.perl.org/perlthrtut.html
<http://perldoc.perl.org/perlthrtut.html> .

After reading the document and trying out a test script myself. Can
someone tell me what I'm doing something wrong? It's a simple copy
function that copies a big file ~50MB, but I was hoping that the copying
happens in parallel but its not. Any ideas what I need to do? I'll like
to try the boss-worker and pipeline method. any information would great.
thanks for your help.

Here is my code?

use threads;

use File::NCopy <file::NCopy>  qw (copy);

my $FILE='c:\tmp\ADK61292p-Explorer8010hd-ATSC-SA-pKey.zip';

my $DIR1='C:\tmp\test1';

my $DIR2='C:\tmp\test2';

my $THREAD_1 = threads->create(\©TOTESTAREA, ${FILE}, ${DIR1});
print "Thread 1" . $THREAD_1->join() ." is done\n";



my $THREAD_2 = threads->create(\©TOTESTAREA, ${FILE}, ${DIR2});
print "Thread 2" . $THREAD_2->join() ." is done\n";



sub COPYTOTESTAREA

{

my ($SOURCE, $DESTINATION) = @_;

copy("${SOURCE}", "${DESTINATION}");

return "I'm done";

}





- - - - - Appended by Scientific Atlanta, a cisco company - - - - - 
This e-mail and any attachments may contain information which is confidentia
l,
proprietary, privileged or otherwise protected by law. The information issol
ely
intended for the named addressee (or a person responsible for delivering it 
to
the addressee). If you are not the intended recipient of this message, you a
re
not authorized to read, print, retain, copy or disseminate this message or a
ny
part of it. If you have received this e-mail in error, please notify the sen
der
immediately by return e-mail and delete it from your computer.

Report this thread to moderator Post Follow-up to this message
Old Post
Wong, Danny H.
04-01-08 04:16 AM


Re: Simple Thread question
I think your problem is the join().  Do not join the thread directly
after creating it.

Create both threads then join().


On Mon, 2008-03-31 at 16:01 -0700, Wong, Danny H. wrote:
> Hi Thread Guru's,
>     I'm just reading up on Perl threads for the first time from
> http://perldoc.perl.org/perlthrtut.html
> <http://perldoc.perl.org/perlthrtut.html> .
>
> After reading the document and trying out a test script myself. Can
> someone tell me what I'm doing something wrong? It's a simple copy
> function that copies a big file ~50MB, but I was hoping that the copying
> happens in parallel but its not. Any ideas what I need to do? I'll like
> to try the boss-worker and pipeline method. any information would great.
> thanks for your help.
>
> Here is my code?
>
> use threads;
>
> use File::NCopy <file::NCopy>  qw (copy);
>
> my $FILE='c:\tmp\ADK61292p-Explorer8010hd-ATSC-SA-pKey.zip';
>
> my $DIR1='C:\tmp\test1';
>
> my $DIR2='C:\tmp\test2';
>
> my $THREAD_1 = threads->create(\©TOTESTAREA, ${FILE}, ${DIR1});
> print "Thread 1" . $THREAD_1->join() ." is done\n";
>
>
>
> my $THREAD_2 = threads->create(\©TOTESTAREA, ${FILE}, ${DIR2});
> print "Thread 2" . $THREAD_2->join() ." is done\n";
>
>
>
> sub COPYTOTESTAREA
>
> {
>
> my ($SOURCE, $DESTINATION) = @_;
>
> copy("${SOURCE}", "${DESTINATION}");
>
> return "I'm done";
>
> }
>
>
>
>
>
>      - - - - - Appended by Scientific Atlanta, a cisco company - - - - -
> This e-mail and any attachments may contain information which is confident
ial,
> proprietary, privileged or otherwise protected by law. The information is 
solely
> intended for the named addressee (or a person responsible for delivering i
t to
> the addressee). If you are not the intended recipient of this message, you
 are
> not authorized to read, print, retain, copy or disseminate this message or
 any
> part of it. If you have received this e-mail in error, please notify the s
ender
> immediately by return e-mail and delete it from your computer.


Report this thread to moderator Post Follow-up to this message
Old Post
Christopher Fowler
04-01-08 04:16 AM


RE: Simple Thread question
Hi Chris,
Thanks for your replay. I realized that  after sending the
email... Looking at to much code will do this to you...

-----Original Message-----
From: Christopher Fowler [mailto:cfowler@outpostsentinel.com]=20
Sent: Monday, March 31, 2008 4:20 PM
To: Wong, Danny H.
Cc: perl-ithreads@perl.org
Subject: Re: Simple Thread question

I think your problem is the join().  Do not join the thread directly
after creating it.

Create both threads then join().


On Mon, 2008-03-31 at 16:01 -0700, Wong, Danny H. wrote:
> Hi Thread Guru's,
>     I'm just reading up on Perl threads for the first time from=20
> http://perldoc.perl.org/perlthrtut.html
> <http://perldoc.perl.org/perlthrtut.html> . =20
>=20
> After reading the document and trying out a test script myself. Can=20
> someone tell me what I'm doing something wrong? It's a simple copy=20
> function that copies a big file ~50MB, but I was hoping that the=20
> copying happens in parallel but its not. Any ideas what I need to do?=20
> I'll like to try the boss-worker and pipeline method. any information
would great.
> thanks for your help.
>=20
> Here is my code?
>=20
> use threads;
>=20
> use File::NCopy <file::NCopy>  qw (copy);
>=20
> my $FILE=3D'c:\tmp\ADK61292p-Explorer8010hd-ATSC-SA-pKey.zip';
>=20
> my $DIR1=3D'C:\tmp\test1';
>=20
> my $DIR2=3D'C:\tmp\test2';
>=20
> my $THREAD_1 =3D threads->create(\©TOTESTAREA, ${FILE}, ${DIR1});=20
> print "Thread 1" . $THREAD_1->join() ." is done\n";
>=20
> =20
>=20
> my $THREAD_2 =3D threads->create(\©TOTESTAREA, ${FILE}, ${DIR2});=20
> print "Thread 2" . $THREAD_2->join() ." is done\n";
>=20
> =20
>=20
> sub COPYTOTESTAREA
>=20
> {
>=20
> my ($SOURCE, $DESTINATION) =3D @_;
>=20
> copy("${SOURCE}", "${DESTINATION}");
>=20
> return "I'm done";
>=20
> }
>=20
>=20
>=20
>=20
>=20
>      - - - - - Appended by Scientific Atlanta, a cisco company - - - -
-        =20
> This e-mail and any attachments may contain information which is=20
> confidential, proprietary, privileged or otherwise protected by law.=20
> The information is solely intended for the named addressee (or a=20
> person responsible for delivering it to the addressee). If you are not

> the intended recipient of this message, you are not authorized to=20
> read, print, retain, copy or disseminate this message or any part of=20
> it. If you have received this e-mail in error, please notify the
sender immediately by return e-mail and delete it from your computer.


Report this thread to moderator Post Follow-up to this message
Old Post
Wong, Danny H.
04-01-08 04:16 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

ithreads archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:51 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.