The threads module have some problem!

S

sonet

perl 5.8.6(ActivePerl Build 811)
win32
===========================================
#!perl.exe
use t2;
use threads;

$h{luke}=123;
while ( !$DONE )
{
threads->new( \&do_thread);
}
sub do_thread{
print "===========\n";
handle_connection();
}
==========================================
package t2;
use strict;

use vars '@ISA', '@EXPORT' , '%h';
use Errno qw(EWOULDBLOCK);
use Digest::MD5 qw(md5_hex);
require Exporter;


@ISA = 'Exporter';
@EXPORT = qw(handle_connection %h);

sub handle_connection{
print "abc123\n";
print $h{luke} . "\r\n";
}
1;
============================================
The result is show that.(And this is i want!)

abc123
123
-------------
abc123
-------------
abc123
-------------
abc123
123
123
123
============================================
#!perl.exe
use t2;
use threads;
my %h;
$h{luke}=123;
while ( !$DONE )
{
threads->new( \&do_thread);
}
sub do_thread{
print "===========\n";
handle_connection();
}
============================================
But if i defined my %h,the result is like below.... Why?
I can not understand.

abc123

-------------
abc123

-------------
abc123

....
==============================================
Another problem is how can i share %h in thread? Like above
example?? I have try to use my %h : share , It seem can not to
work!
 
P

Paul Lalli

sonet said:
perl 5.8.6(ActivePerl Build 811)
win32
===========================================
#!perl.exe

Please read the posting guidelines for this group. Specifically, please
always use strict; and use warnings; in your code.
use t2;
use threads;

$h{luke}=123;
while ( !$DONE )
{
threads->new( \&do_thread);
}
sub do_thread{
print "===========\n";
^^^^^^^^^^^
The result is show that.(And this is i want!)

abc123
123
-------------
^^^^^^^^^^^^^

You're lying. There is no way to produce this output with this code.
Post real code, and real output. Copy and paste, do not retype.


============================================
#!perl.exe
use t2;
use threads;
my %h;
$h{luke}=123;
while ( !$DONE )
{
threads->new( \&do_thread);
}
sub do_thread{
print "===========\n";
handle_connection();
}
============================================
But if i defined my %h,the result is like below.... Why?

When you declare a lexical variable, such as my %h, that variable is
only accessable in the lexcial scope in which it was declared. In this
case, that's this file. No other file that interacts with this file
has access to it. If you had enabled strict and warnings, Perl would
have told you that %h didn't exist where you were trying to access it.

You may wish to read up on the different scopes of lexical and package
variables, at http://perl.plover.com/FAQs/Namespaces.html "Coping with
Scoping"
==============================================
Another problem is how can i share %h in thread? Like above
example?? I have try to use my %h : share , It seem can not to
work!

I have no idea what that means. If
my %h : share;
is valid Perl code, it's new to me. Can you please provide a cite to
explain what that's supposed to do?

Paul Lalli
 
I

IWM

"Paul Lalli" wrote ...

8>< loadsa stuff
You're lying. There is no way to produce this output with this code.
Post real code, and real output. Copy and paste, do not retype.

WOW!

thats an awfully *Strong* word to use on a group such as this...

wouldnt you feel more comfortable saying something such as...

"You must be mistaken"

or

"are you *sure* about your output"?

well... maybe you wouldnt feel more comfortable writing it.... but I should
surely feel more comfortable about reading such...

Ya know... these *everyones either a liar ... a fool... or an idiot*
attitudes to posts dont exactly encourage people to try and take part
here... and no, that comment is not aimed *only* at you

IWM
 
P

Paul Lalli

IWM said:
"Paul Lalli" wrote ...

8>< loadsa stuff


WOW!

thats an awfully *Strong* word to use on a group such as this...

wouldnt you feel more comfortable saying something such as...

"You must be mistaken"

or

"are you *sure* about your output"?

Absolutely not. I am 100% confident that the script you posted did
not generate the output you posted. You claimed that the script you
posted generated the output you posted. Therefore, you are lying.

If you want help, stop whining about being called on what you did
wrong, and start doing things right - post a short-but-complete script
that illustrates your problem, and the actual output it generates.

Paul Lalli
well... maybe you wouldnt feel more comfortable writing it.... but I should
surely feel more comfortable about reading such...

You've mistaken this for alt.psychology.therapy. We're here to help
you debug your Perl scripts, not to make you comfortable. If you end
up feeling comfortable once your programs are working and/or your
knowledge is increased, that's a bonus.

Paul Lalli
 
B

Brian Wakem

Paul said:
Absolutely not. I am 100% confident that the script you posted did
not generate the output you posted. You claimed that the script you
posted generated the output you posted. Therefore, you are lying.


Lying or wrong.

If you say something that is untrue but are unaware that it is untrue, then
that is not a lie.

The OP may well have been lying though.
 
I

IWM

"Paul Lalli" wrote ...
Absolutely not. I am 100% confident that the script you posted

I didnt post a script...
did not generate the output you posted.

I didnt post any output...
You claimed that the script you posted

*sigh*... I didnt post a script
generated the output you posted.

*sigh*... I didnt post any output...
Therefore, you are lying.

ummmm...okaaaayyyy

<humor>
remind me to punch you in the nose if ever we meet ;-)
If you want help,

I'll be sure to ask properly and follow the guidelines etc etc...
stop whining

who ... me?
about being called on what you did wrong,

wha?... whadido???
and start doing things right

but...but...but i'm not at all sure I did anything wrong (cept point out
what appears to be a bad case of social inadequacy on your part)

8>< a bit

IWM

.... who is a beginner to perl
and would not dream of posting my amatuerish scripts here
for fear of getting burned by those who know better than I....
 
P

Paul Lalli

IWM said:
"Paul Lalli" wrote ...

I didnt post a script...


Gah. Okay. 100% my fault this time. I assumed the person complaining
about my choice of words was the same as OP. My (very big) mistake for
not actually checking on that. Please accept my apologies.
<humor>
remind me to punch you in the nose if ever we meet ;-)
</humor>

It'd probably be deserved.
but...but...but i'm not at all sure I did anything wrong (cept point out
what appears to be a bad case of social inadequacy on your part)

Bah. I'd call it a moderate case at worst... ;-)

Paul Lalli
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top