Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > The threads module have some problem!

Reply
Thread Tools

The threads module have some problem!

 
 
sonet
Guest
Posts: n/a
 
      08-01-2005
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!





 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-01-2005
sonet wrote:
> 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";

^^^^^^^^^^^
<snip>
> 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

 
Reply With Quote
 
 
 
 
IWM
Guest
Posts: n/a
 
      08-01-2005

"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


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-01-2005
IWM wrote:
> "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"?


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

 
Reply With Quote
 
Brian Wakem
Guest
Posts: n/a
 
      08-01-2005
Paul Lalli wrote:

> 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.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
IWM
Guest
Posts: n/a
 
      08-01-2005

"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
</humor>

>
> 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....


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-01-2005
IWM wrote:
> "Paul Lalli" wrote ...
> >
> > Absolutely not. I am 100% confident that the script you posted

>
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to check if some object is included in some module? Jarmo Pertman Ruby 5 08-02-2010 05:26 PM
How to get all variables of some module in that module Alex Gusarov Python 3 10-21-2008 04:03 PM
Is there someone have written some programs about RSA-1024?I have some question. dolphin C++ 3 03-09-2007 02:47 PM
Re: module docstring, documentation,anything? please note is the module type/object NOT some module Maric Michaud Python 0 06-24-2006 12:42 PM
how can a module tell if its caller is using some other module russ.jones2@boeing.com Perl Misc 4 02-15-2006 10:45 PM



Advertisments