Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Threads: Free to wrong pool

by P0w3rK!d (Pilgrim)
on Jun 06, 2003 at 14:20 UTC ( #263682=perlquestion: print w/replies, xml ) Need Help??

P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to run an application that will create multiple threads, do work for all the threads, cleanup the threads with a join, and repeat. I get the following error:

"Free to wrong pool 1e76ba8 not 15d26e8 during global destruction."
What can I do to work around this problem? There was only one post associated with this and it did not answer my questions.
use threads; use threads::shared; our $SHARED_DATA : shared; our @threads = (); # threads our $FINISHED : shared = 0; # for simulation state main(); main ( process() ) init( for () { push @threads, threads->new (\&Foo::run()...); } ) process( init(); finish(); ) sub finish { # our (@threads); { lock $FINISHED; $FINISHED = 1; } $_->join for @threads; } ################### # my class ################### package Foo; use threads; use threads::shared; sub new {} sub run { dothings() {lock $FINISHED; return if $FINISHED;} } sub dothings { lock ($SHARED_DATA); # ... }
Thanks :)

-P0w3rK!d

Minor edit per author - dvergin 2003-06-06

Replies are listed 'Best First'.
Re: Threads: Free to wrong pool
by BrowserUk (Pope) on Jun 06, 2003 at 14:44 UTC

    Sorry! I'd really like to try and help you, but the code you posted does not even compile. There are at least 20 errors. If this is a simplification of your program, could you please post a simplification that compiles, runs and demonstrates the error message that you cite.

    What language are you coding in? Because most of this isn't perl.


    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


      WoW!

      This is a new language called pseudo-perl. I was trying to give you a rough idea of how the code worked. I "assumed" many monks could take a look at it, get the general idea of my problem, and attempt to solve it theoretically. I was not expecting you to compile it, so I apologize.

      -P0w3rK!d

      BrowserUK et al,

      It appears that I cannot run the perl program in question with threads that I turn on and off. I create them, they run, they join, then I try to do it again and somewhere in between it blows up. Here is a similar example to what I am trying to do (and yes..it does compile). Also, attached is a modified version that blows up. Please tell me why you think it blows up? :)

      -P0w3rK!d

        Geez. One copy and an indication of the 4 lines you had changed and how would have been more than enough!

        The reason the modified code fails, is because it wasn't designed to be run in a loop, and you have made no changes to allow it to run in a loop.

        The first problem, one of several, is that the our'd array @elevators is initialised in init_elevator() with the handles of the threads used to runs the elevators are pushed onto this array, but they are never removed. So on the second run, a second set of thread handles are push onto the array, and when finish() is called, it attempts to join to all the threads in the array, accept the handles for the first set are still there, but the associated thread are not. Then went away the first time finish() was called. So you are calling join on non-existant threads, so it blows up in your face.

        It probably shouldn't blow up, but it is still programmer error. When you re-start the code, you need to ensure that all the globals, our vars, are re-set to ther initial state.

        There are many other globals used. There are several other problems with the design of this program too. Not a great design, but it is meant as a demonstration of the concepts rather than working level code.


        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


        I tried running #2 and put a breakpoint at finish(). The threads were running fine:

        When I stepped over finish, the application crashed as follows:

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://263682]
Approved by broquaint
Front-paged by castaway
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2019-12-11 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?