in reply to cleanly exiting threads

A thread exited while 2 threads were running. panic: MUTEX_LOCK (22) op.c:352 during global destruction.

The first error may be due to your detached threads not returning. A thread must return (or reach the end of it's code block) before it can be joined or cleanly exited. Your thread may be hanging in that while<$out> loop.


I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: cleanly exiting threads
by JoeKamel (Acolyte) on Aug 13, 2008 at 19:30 UTC
    I would agree, except that i get this message even when I recieve the ENDEND on the other end of the queue for every test (or thread, since I have 1 thread per test + the one to rule them all).

    in perl 5.8.8 is there any equivalent of thread->exit()? Can I explicitly kill threads in anyway?

    interestingly enough if i do a threads->list() right before the main script exits, I don't get any response.

    In this run, I only have two threads, (i.e. one test running), plus thread 0 and it is still reporting exiting with two running.

    The code:
    my @list = threads->list(); print Dumper(\@list); print "\ntotal time: ", format_time( tv_interval($t0) ), "\n"; __END__
    The output:
    $VAR1 = []; total time: 0:1:1.26 A thread exited while 2 threads were running.
      I don't use Thread::Queue myself, but I had this old sample around that says it's kindof obsolete, I may be wrong. Maybe try this style?
      #!/usr/bin/perl #leaks memory- Threads::Queue is for the old Threads <5.7 use strict; use threads; use Thread::Queue; my @threads; my $thread; my $q = Thread::Queue->new(); $q->enqueue(1..100000); print "Items in the queue: ",$q->pending,"\n"; for (1..5) { push @threads, threads->new(\&ttest); print "spawned thread:"; } foreach $thread (@threads){ $thread->join; } sub ttest { while (my $cnt = $q->pending) { my $item = $q->dequeue; print "$cnt\n"; last if $cnt == 0 ; } }

      I'm not really a human, but I play one on earth Remember How Lucky You Are