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.
43 The hook will also be called when pseudo-forks (i.e. processes spawn on Windows for the C<fork> emulation) terminate.
52 Specify that the given block or code reference C<$coderef> will have to be called (in void context, without arguments) every time a thread or a pseudo-fork terminates.
59 For joined threads, it will be called when C<join> succeeds, after any C<END> block local to the spawn thread ;
63 For detached threads, it will be called if and only if the thread terminates before the main thread, and the hook will then fire at global C<END> time ;
67 For pseudo-forks, it will be called when C<waitpid> succeeds, after any C<END> block local to the spawn process but before any global C<END> block ;
71 It will never trigger for the destruction of the main thread.
79 sub register (&) { push @callbacks, shift }
81 sub _CLEANUP { $_->() for @callbacks }
92 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.
100 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
104 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.
108 You can find documentation for this module with the perldoc command.
110 perldoc Thread::Cleanup
112 =head1 ACKNOWLEDGEMENTS
114 Inspired by a question from TonyC on #p5p.
116 =head1 COPYRIGHT & LICENSE
118 Copyright 2009,2010,2013,2014 Vincent Pit, all rights reserved.
120 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
124 1; # End of Thread::Cleanup