develooper Front page | perl.perl5.porters | Postings from April 2018

Re: [perl #133021] Removed the word "discouraged" from threads'documentation

Thread Previous | Thread Next
Dave Mitchell
April 9, 2018 10:39
Re: [perl #133021] Removed the word "discouraged" from threads'documentation
Message ID:
On Mon, Apr 09, 2018 at 12:18:10PM +0300, Sawyer X wrote:
> On 04/09/2018 10:51 AM, Dave Mitchell wrote:
> > On Sun, Apr 08, 2018 at 10:23:20PM +0000, Christian Walde wrote:
> >> - perl threads can work fine under a certain load, but crash randomly once
> >> the load becomes too big
> >> - perl threads can work fine on one computer, but crash randomly on another
> >> due to slight module differences
> > Is this based on the idea that the ithreads implementation itself is
> > inherently buggy, or that some modules may not be thread-safe.
> >
> > I'd be surprised if the former, and if the latter, surely that applies
> > to any "real" threading implementation in any programming language?
> Could you please expand on this, Dave?

1) I think the perl ithreads implementation is fairly bug-free and stable
these days.

2) If one's threaded code randomly craps out due to a 3rd party module
being non-thread-safe, or supposedly thread-safe but buggy, then that's an
issue with the third-party module. In principle any programming language
will struggle with threads if used with a 3rd-party library that isn't

Perl's threads are supposedly safe at the perl language level. For
example, if two threads simultaneously try to push a value to the same
array, then
    a) the internal representation of the array (AV etc) won't be
    b) both elements will get pushed;
    c) perl won't guarantee which order they're pushed in.

This is a lot better guarantee than threads in C for example.

The main danger area is with XS modules; pure perl modules should
at least not corrupt the interpreter state;  whether they work correctly
(e.g. two threads both trying to update the same data file) is down to
whether the module's author does the correct locking etc.

No matter how many dust sheets you use, you will get paint on the carpet.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About