Skip to content

Commit 9205e6a

Browse files
committed
perlembed, perlthrtut, Clarify threads vs ithreads
This fixes #15573
1 parent 29cc805 commit 9205e6a

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

pod/perlembed.pod

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -927,16 +927,27 @@ perl_construct resets it to C<0>.
927927

928928
Now suppose we have more than one interpreter instance running at the
929929
same time. This is feasible, but only if you used the Configure option
930-
C<-Dusemultiplicity> or the options C<-Dusethreads -Duseithreads> when
931-
building perl. By default, enabling one of these Configure options
932-
sets the per-interpreter global variable C<PL_perl_destruct_level> to
933-
C<1>, so that thorough cleaning is automatic and interpreter variables
934-
are initialized correctly. Even if you don't intend to run two or
935-
more interpreters at the same time, but to run them sequentially, like
936-
in the above example, it is recommended to build perl with the
937-
C<-Dusemultiplicity> option otherwise some interpreter variables may
938-
not be initialized correctly between consecutive runs and your
939-
application may crash.
930+
C<-Dusemultiplicity> or either of the options C<-Dusethreads
931+
-Duseithreads> when building perl. By default, enabling one of these
932+
Configure options sets the per-interpreter global variable
933+
C<PL_perl_destruct_level> to C<1>, so that thorough cleaning is
934+
automatic and interpreter variables are initialized correctly. Even if
935+
you don't intend to run two or more interpreters at the same time, but
936+
to run them sequentially, like in the above example, it is recommended
937+
to build perl with the C<-Dusemultiplicity> option otherwise some
938+
interpreter variables may not be initialized correctly between
939+
consecutive runs and your application may crash.
940+
941+
(It used to be that there were two forms of threads, with C<ithreads>
942+
appearing later. But C<ithreads> proved to be superior, and support for
943+
the older model was removed in Perl v5.10. But the documentation and
944+
code have never been purged of the earlier terminology; and perhaps some
945+
newer model will come along to supplant C<ithreads>, so it seems best to
946+
retain both. If you don't care about the threading model used, use
947+
plain C<usethreads> to protect your code from having to change with future
948+
developments. If your code is dependent on the C<ithreads> model, use
949+
C<useithreads> to make sure you will always get that. This applies as well
950+
to the C language symbols C<USE_THREADS> and C<USE_ITHREADS>.)
940951

941952
See also L<perlclib/Dealing with embedded perls and threads>.
942953

pod/perlthrtut.pod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ between threads must be explicit. The user-level interface for I<ithreads>
1313
uses the L<threads> class.
1414

1515
B<NOTE>: There was another older Perl threading flavor called the 5.005 model
16-
that used the L<threads> class. This old model was known to have problems, is
16+
that used the L<Thread> class. This old model was known to have problems, was
1717
deprecated, and was removed for release 5.10. You are
1818
strongly encouraged to migrate any existing 5.005 threads code to the new
1919
model as soon as possible.
@@ -25,6 +25,15 @@ have C<use5005threads=define> you have 5.005 threads.
2525
If you have neither, you don't have any thread support built in.
2626
If you have both, you are in trouble.
2727

28+
In more modern times, the terms C<ithreads> and C<threads> are
29+
synonymous, and are used interchangeably. The best practice is to use
30+
C<useithreads> if your code is dependent on something specific about that
31+
implementation, and to use C<usethreads> if it isn't. That way, in the
32+
very unlikely event that some new threading model comes along, your code
33+
is more protected from needing to change. (The corresponding symbols at
34+
the C language level are C<USE_ITHREADS> and C<USE_THREADS>; these are
35+
currently totally synonymous, but not absolutely guaranteed to remain so.)
36+
2837
The L<threads> and L<threads::shared> modules are included in the core Perl
2938
distribution. Additionally, they are maintained as separate modules on
3039
CPAN, so you can check there for any updates.

0 commit comments

Comments
 (0)