batkins is correct. The error message simply means that you didn't clean up the threads you started when your program terminated. The usual strategy to avoid the message is to retain the thread ids (as returned by the thread->new() call) and then call the join() method on them prior to exiting your program.

However, in order for you to be able to join your threads, you need to arrange for them to terminate. As the threads module stands now, there is no simple mechanism for killing a thread, so you need to arrange for it to die of its own volition.

The usual mechanism for doing this is to use a shared variable allocated in your main thread prior to spinning the thread(s) as a flag to tell your threads when to die.

use strict; use threads; use threads::shared; my $flag : shared = 1; sub thread_code { while( $flag ) { # Do your thread stuff here # but make sure it loops every now and then # so that you will see the flag change } } my @threads = map{ threads->new( \&thread_code ) ; } 1 .. 4; ... # when you get told to finish by the user # or otherwise decide to exit. EXIT{ $flag = 0; # tell the kids its time to go $_->join() for @threads; # Wait for them # and go. }

All of that said, you appear from your brief description to be trying to use a perl object across threads. This doesn't work!

It may seem to work okay initially, but it is fraught with problems. Any object allocated prior to you starting your threads will be replicated to each of your threads, but they will be different copies of the object.

Any attempts made to use a single object from multiple threads is going to at best give you catastrophic failures (Perl itself will segfault), or at worst, result in myriad and ever changing "strange errors" that are very hard to track down.

This is not to say that you cannot use Net::Aim with threads at all. It just means that you will have to understand the requirements and limitations and use threads properly to do so. At the moment, there are very few good examples of using threads available. Perhaps Things you need to know before programming Perl ithreads this recent post by our resident threads expert would be a good place to start before moving on to perlthrtut.

You could also do a super search for "use threads" and look at some of the most recent stuff posted here. Ignore anything much before the start of this year as it is likely that it relates to the earlier and now defunct pThreads implementation rather than the new (since 5.8.0. You are using 5.8.x aren't you?) iThreads.

If your serious about pursuing this, then you should really make sure that you have at least perl 5.8.1 (which is not yet available from AS!) as earlier builds had fairly severe problems with memory leaks under some circumstances.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: Threads and Net::AIM by BrowserUk
in thread Threads and Net::AIM by webmasterbstempin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.