line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Thread::Cleanup; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24062
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
85
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
93
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Thread::Cleanup - Hook thread destruction. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.05 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
BEGIN { |
21
|
1
|
|
|
1
|
|
3
|
$VERSION = '0.05'; |
22
|
1
|
|
|
|
|
6
|
require XSLoader; |
23
|
1
|
|
|
|
|
743
|
XSLoader::load(__PACKAGE__, $VERSION); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Thread::Cleanup; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use threads; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Thread::Cleanup::register { |
33
|
|
|
|
|
|
|
my $tid = threads->tid(); |
34
|
|
|
|
|
|
|
warn "Thread $tid finished\n"; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module allows you to hook thread destruction without fiddling with the internals of L. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
It acts globally on all the threads that may spawn anywhere in your program, with the exception of the main thread. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 FUNCTIONS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 C |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
register { ... }; |
48
|
|
|
|
|
|
|
®ister($coderef); |
49
|
|
|
|
|
|
|
|
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. |
51
|
|
|
|
|
|
|
More precisely, |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over 4 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item * |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
it will always be called before the joining for joined threads ; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * |
60
|
|
|
|
|
|
|
|
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 time ; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item * |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
it won't trigger for the destruction of the main thread. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my @callbacks; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
1
|
|
sub register (&) { push @callbacks, shift } |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
|
|
sub _CLEANUP { $_->() for @callbacks } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 EXPORT |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
None. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L 5.8. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
A C compiler. |
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. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L 1.07. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Vincent Pit, C<< >>, L. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 BUGS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SUPPORT |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
perldoc Thread::Cleanup |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Inspired by a question from TonyC on #p5p. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Copyright 2009,2010,2013 Vincent Pit, all rights reserved. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; # End of Thread::Cleanup |