This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ca8c4e4abcf4b54a704e8c5231349b4d73eaa5a2
[metaconfig.git] / U / threads / usethreads.U
1 ?RCS: $Id: usethreads.U,v $
2 ?RCS:
3 ?RCS: Copyright (c) 1998-2000 Andy Dougherty
4 ?RCS:
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
7 ?RCS:
8 ?RCS: $Log: usethreads.U,v $
9 ?RCS:
10 ?MAKE:usethreads useithreads use5005threads d_oldpthreads usereentrant: \
11         Myread Oldconfig Setvar test cat useperlio patchlevel
12 ?MAKE:  -pick add $@ %<
13 ?Y:TOP
14 ?S:usethreads:
15 ?S:     This variable conditionally defines the USE_THREADS symbol,
16 ?S:     and indicates that Perl should be built to use threads.
17 ?S:.
18 ?S:useithreads:
19 ?S:     This variable conditionally defines the USE_ITHREADS symbol,
20 ?S:     and indicates that Perl should be built to use the interpreter-based
21 ?S:     threading implementation.
22 ?S:.
23 ?S:use5005threads:
24 ?S:     This variable conditionally defines the USE_5005THREADS symbol,
25 ?S:     and indicates that Perl should be built to use the 5.005-based
26 ?S:     threading implementation. Only valid up to 5.8.x.
27 ?S:.
28 ?X: I'm putting old_pthreads in this unit because it might eventually
29 ?X: be part of an automatic determination to see if we can use threads
30 ?X: at all.
31 ?S:d_oldpthreads:
32 ?S:     This variable conditionally defines the OLD_PTHREADS_API symbol,
33 ?S:     and indicates that Perl should be built to use the old
34 ?S:     draft POSIX threads API.  This is only potentially meaningful if
35 ?S:     usethreads is set.
36 ?S:.
37 ?S:usereentrant:
38 ?S:     This variable conditionally defines the USE_REENTRANT_API symbol,
39 ?S:     which indicates that the thread code may try to use the various
40 ?S:     _r versions of library functions.  This is only potentially
41 ?S:     meaningful if usethreads is set and is very experimental, it is
42 ?S:     not even prompted for.
43 ?S:.
44 ?C:USE_ITHREADS:
45 ?C:     This symbol, if defined, indicates that Perl should be built to
46 ?C:     use the interpreter-based threading implementation.
47 ?C:.
48 ?C:USE_5005THREADS:
49 ?C:     This symbol, if defined, indicates that Perl should be built to
50 ?C:     use the 5.005-based threading implementation.
51 ?C:     Only valid up to 5.8.x.
52 ?C:.
53 ?C:USE_THREADS:
54 ?C:     This symbol, if defined, indicates that Perl should
55 ?C:     be built to use threads.  At present, it is a synonym for
56 ?C:     USE_5005THREADS for perl older than 5.8 and USE_ITHREADS
57 ?C:     for 5.8.x and newer, but eventually the source ought to be
58 ?C:     changed to use this to mean _any_ threading implementation.
59 ?C:.
60 ?C:OLD_PTHREADS_API:
61 ?C:     This symbol, if defined, indicates that Perl should
62 ?C:     be built to use the old draft POSIX threads API.
63 ?C:.
64 ?C:USE_REENTRANT_API:
65 ?C:     This symbol, if defined, indicates that Perl should
66 ?C:     try to use the various _r versions of library functions.
67 ?C:     This is extremely experimental.
68 ?C:.
69 ?H:#$use5005threads     USE_5005THREADS         /**/
70 ?H:#$useithreads        USE_ITHREADS            /**/
71 ?H:?%<:#if defined(USE_5005THREADS) && !defined(USE_ITHREADS)
72 ?H:?%<:#define          USE_THREADS             /* until src is revised*/
73 ?H:?%<:#endif
74 ?H:#$d_oldpthreads      OLD_PTHREADS_API                /**/
75 ?H:#$usereentrant       USE_REENTRANT_API       /**/
76 ?H:.
77 ?LINT:set usethreads useithreads use5005threads d_oldpthreads usereentrant
78 ?INIT:: set usethreads on the Configure command line to enable threads.
79 ?INIT:usereentrant='undef'
80 ?F:!usethreads.cbu
81 ?X: We should really have some explanatory text here, and some
82 ?X: automatic setting of sensible defaults.
83 case "$usethreads" in
84 $define|true|[yY]*)     dflt='y';;
85 *)     # Catch case where user specified ithreads or 5005threads but
86        # forgot -Dusethreads (A.D. 4/2002)
87        case "$useithreads$use5005threads" in
88        *$define*)      
89                 case "$useperlio" in
90                 "$define")      dflt='y' ;;
91                 *)              dflt='n' ;;
92                 esac
93                 ;;
94        *)       dflt='n';;
95        esac
96        ;;
97 esac
98 cat <<EOM
99
100 Perl can be built to take advantage of threads on some systems.
101 To do so, Configure can be run with -Dusethreads.
102
103 Note that Perl built with threading support runs slightly slower
104 and uses more memory than plain Perl. The current implementation
105 is believed to be stable, but it is fairly new, and so should be
106 treated with caution.
107
108 If this doesn't make any sense to you, just accept the default '$dflt'.
109 EOM
110 rp='Build a threading Perl?'
111 . ./myread
112 case "$ans" in
113 y|Y)    val="$define" ;;
114 *)      val="$undef" ;;
115 esac
116 set usethreads
117 eval $setvar
118
119 if $test $patchlevel -lt 9; then
120     case "$usethreads" in
121     $define)
122         $cat <<EOM
123
124 Since release 5.6, Perl has had two different threading implementations,
125 the newer interpreter-based version (ithreads) with one interpreter per
126 thread, and the older 5.005 version (5005threads).
127 The 5005threads version is effectively unmaintained and will probably be
128 removed in Perl 5.10, so there should be no need to build a Perl using it
129 unless needed for backwards compatibility with some existing 5.005threads
130 code.
131
132 EOM
133         : Default to ithreads unless overridden on command line or with
134         : old config.sh
135         dflt='y'
136         case "$use5005threads" in
137                 $define|true|[yY]*) dflt='n';;
138         esac
139         case "$useithreads" in
140                 $undef|false|[nN]*) dflt='n';;
141         esac
142         rp='Use the newer interpreter-based ithreads?'
143         . ./myread
144         case "$ans" in
145         y|Y)    val="$define" ;;
146         *)      val="$undef" ;;
147         esac
148         set useithreads
149         eval $setvar
150         : Now set use5005threads to the opposite value.
151         case "$useithreads" in
152         $define) val="$undef" ;;
153         *) val="$define" ;;
154         esac
155         set use5005threads
156         eval $setvar
157         ;;
158     *)
159         useithreads="$undef"
160         use5005threads="$undef"
161         ;;
162     esac
163
164 ?X: This is not supposed to be possible but with some trickery, maybe.
165     case "$useithreads$use5005threads" in
166     "$define$define")
167         $cat >&4 <<EOM
168
169 You cannot have both the ithreads and the 5.005 threads enabled
170 at the same time.  Disabling the 5.005 threads since they are
171 much less stable than the ithreads.
172
173 EOM
174         use5005threads="$undef"
175         ;;
176     esac
177
178 else
179 : perl-5.9.x and later
180
181     if test X"$usethreads" = "X$define"; then
182         case "$use5005threads" in
183             $define|true|[yY]*)
184                 $cat >&4 <<EOM
185
186 5.005 threads has been removed for 5.10.  Perl will be built using ithreads.
187
188 EOM
189             ;;
190         esac
191     fi
192
193     use5005threads="$undef"
194     useithreads="$usethreads"
195 fi
196
197 if test X"$usethreads" = "X$define" -a "X$useperlio" = "Xundef"; then
198         cat >&4 <<EOF
199 ***
200 *** To build with ithreads you must also use the PerlIO layer.
201 *** Cannot continue, aborting.
202 ***
203 EOF
204         exit 1
205 fi
206
207 ?X: Check out what kind of threads api we have
208 case "$d_oldpthreads" in
209 '')     : Configure tests would be welcome here.  For now, assume undef.
210         val="$undef" ;;
211 *)      val="$d_oldpthreads" ;;
212 esac
213 set d_oldpthreads
214 eval $setvar
215
216 ?X: In general, -lpthread needs to come before -lc but after other
217 ?X: libraries such as -lgdbm and such like. We assume here that -lc
218 ?X: is present in libswanted. If that fails to be true, then this
219 ?X: can be changed to add pthread to the very end of libswanted.
220
221 : Look for a hint-file generated 'call-back-unit'.  If the
222 : user has specified that a threading perl is to be built,
223 : we may need to set or change some other defaults.
224 if $test -f usethreads.cbu; then
225     echo "Your platform has some specific hints regarding threaded builds, using them..."
226     . ./usethreads.cbu
227 else
228     case "$usethreads" in
229         "$define"|true|[yY]*)
230                 $cat <<EOM
231 (Your platform does not have any specific hints for threaded builds.
232  Assuming POSIX threads, then.)
233 EOM
234         ;;
235     esac
236 fi
237