2

According to the INSTALL docs,

On some platforms, perl can be compiled with support for threads. To enable this, run

sh Configure -Dusethreads

The default is to compile without thread support.

With the thread implementation being pretty stable, how come it isn't a default build option? The build option seems to be set by at least Debian and Alpine Linux. Is there any good reason to build Perl without threads? What are the downsides to threaded perl?

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • Nevertheless Unix distributions such as FreeBSD, Debian, Ubuntu, and CloudLinux ship with Perl built with threads support usually displayed as `x86_64-linux-thread-multi`. – Elvin Nov 17 '22 at 08:30
  • That can be checked with `perl -V:useithreads`. The output will be either `useithreads='define` or `useithreads='undef';`. – Elvin Nov 17 '22 at 13:54

1 Answers1

5

Because threaded builds of Perl are 10% slower[1] than non-threaded, non-multiplicity[2] builds.


  1. Your experience may vary.
  2. Multiplicity is supporting multiple instances of the interpreter in one program. -DMULTIPLICITY is implied and required by -Dusethreads (since each thread has its own interpreter).
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Slower even if you don't `use threads`? – Elvin Nov 17 '22 at 08:32
  • The threads [manual](https://perldoc.perl.org/threads) warns: _The use of interpreter-based threads in perl is officially discouraged._ – Elvin Nov 17 '22 at 08:33
  • @Elvin, That is not a factor. They are fully supported and safe to use. Strawberry Perl, Active Perl, and Linux distros all enable threading support, so virtually every `perl` has thread support. When asked, P5P explained the warning was there because ...people on the IRC channel got tired of handling thread-related questions. wtf. – ikegami Nov 17 '22 at 13:43
  • I agree, I am all for threads in Perl. I wanted to ask you if the your "10% slower" statement applies even if we don't `use threads;` (ie. import the pragma) inside our Perl script? – Elvin Nov 17 '22 at 13:50
  • By the way, unfortunately [`perlbrew`](https://perlbrew.pl/) doesn't compile with threads by default as well. I use it to install and run Perl 5.36 on Debian 11, and so does cPanel (`/usr/local/cpanel/3rdparty/bin/perl`). – Elvin Nov 17 '22 at 13:51
  • @Evlin, Yes. The loss is surely do to the use of context arguments and indirects to support multiple interpreters (`-DMULTIPLICITY`). This happens whether the process has mutliple interpreters or not. – ikegami Nov 17 '22 at 13:58
  • @Evlin perlbrew is silent on the matter. It passes whatever options you provide to the installer. – ikegami Nov 17 '22 at 14:01