source: trunk/essentials/dev-lang/perl/ext/threads/threads.pm@ 3212

Last change on this file since 3212 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 8.3 KB
Line 
1package threads;
2
3use 5.008;
4use strict;
5use warnings;
6use Config;
7
8BEGIN {
9 unless ($Config{useithreads}) {
10 my @caller = caller(2);
11 die <<EOF;
12$caller[1] line $caller[2]:
13
14This Perl hasn't been configured and built properly for the threads
15module to work. (The 'useithreads' configuration option hasn't been used.)
16
17Having threads support requires all of Perl and all of the XS modules in
18the Perl installation to be rebuilt, it is not just a question of adding
19the threads module. (In other words, threaded and non-threaded Perls
20are binary incompatible.)
21
22If you want to the use the threads module, please contact the people
23who built your Perl.
24
25Cannot continue, aborting.
26EOF
27 }
28}
29
30use overload
31 '==' => \&equal,
32 'fallback' => 1;
33
34BEGIN {
35 warn "Warning, threads::shared has already been loaded. ".
36 "To enable shared variables for these modules 'use threads' ".
37 "must be called before any of those modules are loaded\n"
38 if($threads::shared::threads_shared);
39}
40
41require Exporter;
42require DynaLoader;
43
44our @ISA = qw(Exporter DynaLoader);
45
46our %EXPORT_TAGS = ( all => [qw(yield)]);
47
48our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
49
50our @EXPORT = qw(
51async
52);
53our $VERSION = '1.07';
54
55
56# || 0 to ensure compatibility with previous versions
57sub equal { ($_[0]->tid == $_[1]->tid) || 0 }
58
59# use "goto" trick to avoid pad problems from 5.8.1 (fixed in 5.8.2)
60# should also be faster
61sub async (&;@) { unshift @_,'threads'; goto &new }
62
63sub object {
64 return undef unless @_ > 1;
65 foreach (threads->list) {
66 return $_ if $_->tid == $_[1];
67 }
68 return undef;
69}
70
71$threads::threads = 1;
72
73bootstrap threads $VERSION;
74
75# why document 'new' then use 'create' in the tests!
76*create = \&new;
77
78# Preloaded methods go here.
79