2 Thread::Cleanup - Hook thread destruction.
12 Thread::Cleanup::register {
13 my $tid = threads->tid();
14 warn "Thread $tid finished\n";
18 This module allows you to hook thread destruction without fiddling with
19 the internals of threads.
21 It acts globally on all the threads that may spawn anywhere in your
22 program, with the exception of the main thread.
24 The hooks registered with this module will also be called when
25 pseudo-forks (i.e. processes spawn on Windows for the "fork" emulation)
33 Specify that the given block or code reference $coderef will have to be
34 called (in void context, without arguments) every time a thread or a
35 pseudo-fork terminates. More precisely :
37 * For joined threads, it will be called when "join" succeeds, after
38 any "END" block local to the spawn thread ;
40 * For detached threads, it will be called if and only if the thread
41 terminates before the main thread, and the hook will then fire at
44 * For pseudo-forks, it will be called when "waitpid" succeeds, after
45 any local or global "END" block ;
47 * It will never trigger for the destruction of the main thread.
55 A C compiler. This module may happen to build with a C++ compiler as
56 well, but don't rely on it, as no guarantee is made in this regard.
63 Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
66 Please report any bugs or feature requests to "bug-thread-cleanup at
67 rt.cpan.org", or through the web interface at
68 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Thread-Cleanup>. I will
69 be notified, and then you'll automatically be notified of progress on
70 your bug as I make changes.
73 You can find documentation for this module with the perldoc command.
75 perldoc Thread::Cleanup
78 Inspired by a question from TonyC on #p5p.
81 Copyright 2009,2010,2013,2014 Vincent Pit, all rights reserved.
83 This program is free software; you can redistribute it and/or modify it
84 under the same terms as Perl itself.