1 package Thread::Cleanup;
10 Thread::Cleanup - Hook thread destruction.
23 XSLoader::load(__PACKAGE__, $VERSION);
32 Thread::Cleanup::register {
33 my $tid = threads->tid();
34 warn "Thread $tid finished\n";
39 This module allows you to hook thread destruction without fiddling with the internals of L<threads>.
41 It acts globally on all the threads that may spawn anywhere in your program, with the exception of the main thread.
45 =head2 C<register BLOCK>
47 Specify that the C<BLOCK> will have to be called (in void context, without arguments) every time a thread finishes its job.
54 it will always be called before the joining for joined threads ;
58 it will be called for detached threads if and only if they terminate before the main thread, and the hook will then fire at C<END> time ;
62 it won't trigger for the destruction of the main thread.
70 sub register (&) { push @callbacks, shift }
72 sub _CLEANUP { $_->() for @callbacks }
88 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
92 Please report any bugs or feature requests to C<bug-thread-cleanup at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Thread-Cleanup>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
96 You can find documentation for this module with the perldoc command.
98 perldoc Thread::Cleanup
100 =head1 ACKNOWLEDGEMENTS
102 Inspired by a question from TonyC on #p5p.
104 =head1 COPYRIGHT & LICENSE
106 Copyright 2009,2010 Vincent Pit, all rights reserved.
108 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
112 1; # End of Thread::Cleanup