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

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

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
April 10, 2018 14:46
Subject:
Re: [perl #133021] Removed the word "discouraged" from threads'documentation
Message ID:
CAHAeAG40zyka4=_D4E1VXoSFhgHgViGo+J1-2AkASRsepUP=Ag@mail.gmail.com
On Tue, Apr 10, 2018 at 4:27 PM, Dave Mitchell <davem@iabyn.com> wrote:

> On Tue, Apr 10, 2018 at 08:40:45PM +0800, Tom Molesworth via perl5-porters
> wrote:
> > We also don't have good documentation on how to make modules thread-safe:
> > I've encountered quite a few Perl developers who are confident that
> thread
> > safety is only an issue with XS.
>
> I'd be one of those, in the sense that the perl language itself is
> thread-safe, and doesn't normally need locks or special handling; but in
> any environment where there are multiple concurrently running threads,
> there will be some extra considerations required.
>

  And yet, documented behaviour of pure-Perl modules breaks under threads.

  Because of this:


> > As an example: far as I recall, the threads.pm documention and perlmod
> page
> > to which they link never explicitly state that ref addresses will be
> > different in each thread:
>
> Since the whole basic principle of ithreads is that data isn't shared by
> default, it would be astonishing if two (non-shared) refs in two different
> threads had the same address.
>

  (And quite a few pure-Perl modules do not expect this.  I don't have a
count of how common it is on CPAN though.)


> > Any
> > time someone asks about thread safety, I point to the "discouraged" line
> in
> > the official documentation and explain that I don't expect my code to
> work
> > when multiple threads are active - "maybe try again if we have a new
> > threads implementation in the future".
>
> Fine - add to the pod in your modules that they're not thread-safe.
>

  How about we make thread support opt-in instead of opt-out?


> > Exposing the API to end users without
> > warnings and clear information about how threads differs from other
> > languages, on the other hand - maybe not ideal.
>
> I am all in favour of having, at the same location as the current
> 'discouraged' text, but instead of it, a big flashing neon sign saying
> that perl threads are a bit different from what you might expect and only
> use them if you understand that (e.g. each thread is a non-shared clone
> of the parent, with memory and start-up-cost implications).
>

  That is, add a warning that threads are unsupported by CPAN modules
unless such support is advertised?


Eirik

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About