Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Use thread with good care, but definitely keep using it

by Revelation (Deacon)
on Mar 14, 2003 at 00:02 UTC ( [id://242896]=note: print w/replies, xml ) Need Help??


in reply to Use thread with good care, but definitely keep using it

Please note that for backwards compatibility threading is not an option (especially with $VER <= perl 5.6). As pfaut also pointed out it's not always the best-option, anyways. The standards for threading aren't altogether clear, either, so I'd rather not use it as a production option for code that will be sent out. Therefore, I treat it much like an experimental function that's pretty far along in its development scale. (somewhere between lvalue and the builtins like open() I've come to trust) As you say "As demos, they are probably fine, but for real applications, this is extremely harmful, and makes absolutely no sense."

However, I prefer to use Net::Server with preforking when I need to create a server to do things. The module deals with a lot of the problems people will have (buffer overlflows, etc.) and is easily extensible. However, as the author asserts, it isn't as popular as the other server implementations (boohooo :O( ), and therefore needs users to write extensions and people to use it. I hope you, as well as other socket server people's try it; I've found it to be a great resource. (It might be interesting to write Net::Server::Threading, since threading is becomming more standardized as time goes on. Just make sure to use 5.8; in your code.)

I say give threading more time (maybe the next major realease of perl 5 and they'll hopefully be more usable in perl 6). Meanwhile IO::Select and fork() seem to provide viable production alternatives.

Gyan Kapur
gkapur@myrealbox.com

Replies are listed 'Best First'.
Re: Re: Use thread with good care, but definitely keep using it
by pg (Canon) on Mar 14, 2003 at 02:36 UTC
    Yes, need to give it more time, but at the same time, should try it out, so more useful info can be feedback to the development.

    Other than the cost of resource, if you ask me to pick one major problem, and only one. I would say that the biggest problem, according to my intensive trial with perl threading, is that bless is not implemented for threading.

    Considering that lots of Perl modules are implemented as object, the bless problem simply made it impossible for you to share things among threads (of course you can share "prime" data types like scalar, array, hash etc.)

    The problem with bless stops me from lots of experiments. As a supporter of perl threading, I hope they can resolve those major problems very soon.
      do you have any more information/links on this bless issue?


      time was, I could move my arms like a bird and...
        The official doc is threads::shared, you can find info about this in the BUGS section.

        Whether there is any online article about this, I am not sure. You may give a search, if find any, please post links here, thanks.

        I created a short script to demo this, just uncomment either of the two commented lines. Compare the results from both cases. You will see that, if %hash itself is shared, you are not be able to assign $hash{VALUE} to an Object of Something correctly. Perl loses the object type, and simple coverts it into an unblessed hashref. Hence, you would not be able to call any method defined on that Object.
        use Something; use threads; use threads::shared; use strict; use warnings; #my %hash : shared; #my %hash; $hash{VALUE} = &share(new Something(1)); print $hash{VALUE}; package Something; sub new { shift; my $self = {}; $self->{VALUE} = shift; bless($self); return $self; } 1; 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://242896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found