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.
50 Specify that the given block or code reference C<$coderef> will have to be called (in void context, without arguments) every time a thread finishes its job.
57 it will always be called before the joining for joined threads ;
61 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 ;
65 it won't trigger for the destruction of the main thread.
73 sub register (&) { push @callbacks, shift }
75 sub _CLEANUP { $_->() for @callbacks }
86 This module may happen to build with a C++ compiler as well, but don't rely on it, as no guarantee is made in this regard.
94 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
98 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.
102 You can find documentation for this module with the perldoc command.
104 perldoc Thread::Cleanup
106 =head1 ACKNOWLEDGEMENTS
108 Inspired by a question from TonyC on #p5p.
110 =head1 COPYRIGHT & LICENSE
112 Copyright 2009,2010 Vincent Pit, all rights reserved.
114 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
118 1; # End of Thread::Cleanup