The threads module have some problem!

Discussion in 'Perl Misc' started by sonet, Aug 1, 2005.

  1. sonet

    sonet Guest

    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!
    sonet, Aug 1, 2005
    #1
    1. Advertising

  2. sonet

    Paul Lalli Guest

    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
    Paul Lalli, Aug 1, 2005
    #2
    1. Advertising

  3. sonet

    IWM Guest

    "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
    IWM, Aug 1, 2005
    #3
  4. sonet

    Paul Lalli Guest

    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
    Paul Lalli, Aug 1, 2005
    #4
  5. sonet

    Brian Wakem Guest

    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
    Brian Wakem, Aug 1, 2005
    #5
  6. sonet

    IWM Guest

    "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....
    IWM, Aug 1, 2005
    #6
  7. sonet

    Paul Lalli Guest

    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
    Paul Lalli, Aug 1, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    2
    Views:
    1,406
    Tommy
    Feb 13, 2004
  2. Maric Michaud
    Replies:
    0
    Views:
    7,181
    Maric Michaud
    Jun 24, 2006
  3. dolphin
    Replies:
    3
    Views:
    359
    rossum
    Mar 9, 2007
  4. Alex Gusarov
    Replies:
    3
    Views:
    269
    Alex Gusarov
    Oct 21, 2008
  5. Jarmo Pertman
    Replies:
    5
    Views:
    128
    Jarmo Pertman
    Aug 2, 2010
Loading...

Share This Page