Mailing List Archive

concurrency list (was Re: Relinquishing Maintenance of Core Modules)
* Leon Timmermans <fawaka@gmail.com> [2021-07-25 13:10:05 +0200]:

> On Sun, Jul 25, 2021 at 1:09 AM David Christensen <dpchrist@holgerdanske.com>
> wrote:
>
> > Whatever is done, I have been wanting a Perl concurrency mailing list
> > for many years.
> >
>
> We don't really need more talking, we need more doing.

This isn't super fair. Concurrency is a big deal and many-faceted.

The ideas of "practical" concurrency is way more important to
perl/Perl's future than virtually any other issue. This includes
Perl OOP. p5p, I agree, is not the place for most of what'd be
captured on any list.

Having a place for "all" to discuss it and attempt to form some
good will in this area (it having been a major point of discord in
the past).

I've recently sought to create an openmp@ list under perl.org, but
was told they are no longer creating them; but to do to any number
of providers to do so. Anything I'd hope to accomplish in an openmp@
list could be accomplished in a p5-concurrency@ list somewhere that
was collaborative.

Off the top of my head there are many topics ripe for discussion:

* ithreads
* forking based things
* async
* "real" threads via OpenMP/pthreads bindings
* perl vs Perl memory models
* atomicity/sequential consistency
* lots more stuff

So as long as it's TIMTOWTDI, I think it's a fabulous idea. Let me
know where to sign up! (#concurrency on irc.perl might be a cool
idea, too; but maybe after).

Cheers,
Brett

>
> Leon

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On Sunday, 25 July 2021, 18:06:16 CEST, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

> The ideas of "practical" concurrency is way more important to
> perl/Perl's future than virtually any other issue. This includes
> Perl OOP.

For what it's worth, I think I agree with this sentiment. We have mostly working, if crippled, OOP. We don't have practical concurrency in a meaningful form. And I know one company that is dumping Perl for Java because, quote "Java can use all of the cores" unquote. There really aren't any popular dynamic languages with a properly working concurrency model (Raku's awesome, but I don't think it's "popular"). We need useful/easy concurrency, though I'm unsure if we'll get it. 
That being said, it's not a zero-sum game. Useful OOP will still be a huge game changer. Give me:

- Concurrency
- OOP
- Signatures
- Some way of defining enforceable types

With that, Perl can come out of the gate swinging.
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
From the keyboard of Ovid via perl5-porters [28.07.21,15:26]:

> On Sunday, 25 July 2021, 18:06:16 CEST, Oodler 577 via perl5-porters
> <perl5-porters@perl.org> wrote:
>
> > The ideas of "practical" concurrency is way more important to
> > perl/Perl's future than virtually any other issue. This includes
> > Perl OOP.
>
> For what it's worth, I think I agree with this sentiment. We have mostly working, if
> crippled, OOP. We don't have practical concurrency in a meaningful form. And I know one
> company that is dumping Perl for Java because, quote "Java can use all of the cores"
> unquote. There really aren't any popular dynamic languages with a properly working
> concurrency model (Raku's awesome, but I don't think it's "popular"). We need useful/easy
> concurrency, though I'm unsure if we'll get it. 

Last time I looked there was MCE which somehow looks meaningful.

> That being said, it's not a zero-sum game. Useful OOP will still be a huge game changer.
> Give me:
>
> * Concurrency
> * OOP
> * Signatures
> * Some way of defining enforceable types
>
> With that, Perl can come out of the gate swinging.
>
> Best,
> Ovid
> -- IT consulting, training, specializing in Perl, databases, and agile development
> http://www.allaroundtheworld.fr/. 
> Buy my book! - http://bit.ly/beginning_perl
>
>

0--gg-

--
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
* shmem <gm@qwurx.de> [2021-07-28 19:32:05 +0200]:
> > From the keyboard of Ovid via perl5-porters [28.07.21,15:26]:
>
> > On Sunday, 25 July 2021, 18:06:16 CEST, Oodler 577 via perl5-porters
> > <perl5-porters@perl.org> wrote:
> >
> > > The ideas of "practical" concurrency is way more important to
> > > perl/Perl's future than virtually any other issue. This includes
> > > Perl OOP.
> >
> > For what it's worth, I think I agree with this sentiment. We have mostly working, if
> > crippled, OOP. We don't have practical concurrency in a meaningful form. And I know one
> > company that is dumping Perl for Java because, quote "Java can use all of the cores"
> > unquote. There really aren't any popular dynamic languages with a properly working
> > concurrency model (Raku's awesome, but I don't think it's "popular"). We need useful/easy
> > concurrency, though I'm unsure if we'll get it.?
>
> Last time I looked there was MCE which somehow looks meaningful.

MCE is useful, but it merely provides a communication fabric for
OS processes.

We also have message passing and "async" options.

What we need is a door into the sharing of memory; if not among
threads (not my goal), surely amoung fork'd processes. Coupled with
atomic synchronization primatives (which we have in some form via
sysopen), this would provide us a path to utilize forks+shared
memory.

I believe there exist some potential pathways to this. One is by
leveraging some aspects of fork (e.g., filehandles remain shared)
and also by looking at some interesting modules on CPAN.

Based on Leon's CPAN repertoire, I think that the expertise is most
certainly among us to present some interesting things.

In this vein, I am making progress on how we could leverage OpenMP
in various perlish and not so perlish ways.

But I digress, a "concurrency" list would certainly be the right
place to do these kinds of explorations. And also maybe just focus
on doing cool things for the good of Perl/perl and not fighting about
what's fake and what's real. :-)

The primary question here is - what's the next step for creating a
collaborative effort amount "all the concurrencies"? Keep in mind,
and true to form, and place would necessarily need to allow parallel
models and approaches to "concurrency". (pun 100% intended).

Cheers,
Brett
>
> > That being said, it's not a zero-sum game. Useful OOP will still be a huge game changer.
> > Give me:
> >
> > * Concurrency
> > * OOP
> > * Signatures
> > * Some way of defining enforceable types
> >
> > With that, Perl can come out of the gate swinging.
> >
> > Best,
> > Ovid
> > --?IT consulting, training, specializing in Perl, databases, and agile development
> > http://www.allaroundtheworld.fr/.?
> > Buy my book! - http://bit.ly/beginning_perl
> >
> >
>
> 0--gg-
>
> --
> _($_=" "x(1<<5)."?\n".q?/)Oo. G?\ /
> /\_?/(q /
> ---------------------------- \__(m.====?.(_("always off the crowd"))."?
> ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}


--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
2021-7-26 0:26 Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

>
> The ideas of "practical" concurrency is way more important to
> perl/Perl's future than virtually any other issue. This includes
> Perl OOP. p5p, I agree, is not the place for most of what'd be
> captured on any list.
>
>
The word "concurrency" is always ambiguous when people talk about
"concurrency".

I hear the this conversation "Perl doesn't have concurrency, so Perl can't
use CPUs in parallel"

But, I know the pre-fork model Perl web applications are using CPUs in
parallel.

I think we need to properly classify concurrency(fork, thread, I/O,
CPU(OpenMP), GPU, coroutine, async/await syntax) before we say we want to
add concurrency.
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
* Yuki Kimoto <kimoto.yuki@gmail.com> [2021-07-29 12:59:36 +0900]:

> 2021-7-26 0:26 Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:
>
> >
> > The ideas of "practical" concurrency is way more important to
> > perl/Perl's future than virtually any other issue. This includes
> > Perl OOP. p5p, I agree, is not the place for most of what'd be
> > captured on any list.
> >
> >
> The word "concurrency" is always ambiguous when people talk about
> "concurrency".
>
> I hear the this conversation "Perl doesn't have concurrency, so Perl can't
> use CPUs in parallel"

The perl run time is sequential. A better way to say it, is that the per
run time's memory model is sequential, meaning there is zero shared memory.

>
> But, I know the pre-fork model Perl web applications are using CPUs in
> parallel.
>
> I think we need to properly classify concurrency(fork, thread, I/O,
> CPU(OpenMP), GPU, coroutine, async/await syntax) before we say we want to
> add concurrency.

I agree 100%. Typically, OpenMP is accomplished at low
level with pthreads.

Note, PDL also has a way to invoke pthreads:

https://metacpan.org/dist/PDL/view/Basic/Pod/ParallelCPU.pod

But, in general your list seems sufficient to start a conversation
somewhere. Each type of "concurrency" can be solved by a variety of
different interface approached (read: CPAN module).

My personal interest is shared memory, even if it's among fork'd
child processes. By my current investigations are looking at using
OpenMP inside of C functions defined using Inline::C.

Brett

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On Sun, Jul 25, 2021 at 5:26 PM Oodler 577 <oodler577@sdf-eu.org> wrote:

> The ideas of "practical" concurrency is way more important to
> perl/Perl's future than virtually any other issue.


I agree it's important, that's why I'm actually working on the issue. To be
precise, an ithreads based (so can actually use multiple processors)
continuation passing style (same model Go uses for its channels) module.

* ithreads
> * forking based things
> * async
> * "real" threads via OpenMP/pthreads bindings
> * perl vs Perl memory models
> * atomicity/sequential consistency
> * lots more stuff
>

You appear to think that ideas are something we lack, they're not. I can
come up with more ideas in an afternoon than I can implement in a year. In
practice, all ideas have either been already done, or are very difficult
(or even impossible) to do. My question to you would be "what are you going
to do to implement any of these ideas?"


> So as long as it's TIMTOWTDI, I think it's a fabulous idea. Let me
> know where to sign up! (#concurrency on irc.perl might be a cool
> idea, too; but maybe after).
>

Mailing lists usually start when a cc: field gets too big (that's literally
how p5p started back in the day), so I would suggest you start with asking
who wants to join.

Leon
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
* Leon Timmermans <fawaka@gmail.com> [2021-07-29 19:34:38 +0200]:

> On Sun, Jul 25, 2021 at 5:26 PM Oodler 577 <oodler577@sdf-eu.org> wrote:
>
> > The ideas of "practical" concurrency is way more important to
> > perl/Perl's future than virtually any other issue.
>
>
> I agree it's important, that's why I'm actually working on the issue. To be
> precise, an ithreads based (so can actually use multiple processors)
> continuation passing style (same model Go uses for its channels) module.
>
> * ithreads
> > * forking based things
> > * async
> > * "real" threads via OpenMP/pthreads bindings
> > * perl vs Perl memory models
> > * atomicity/sequential consistency
> > * lots more stuff
> >
>
> You appear to think that ideas are something we lack, they're not. I can
> come up with more ideas in an afternoon than I can implement in a year. In

This is not what I think; but this is a good example of how the topic of concurrency
nearly always turns into a negative exchange.

> practice, all ideas have either been already done, or are very difficult
> (or even impossible) to do. My question to you would be "what are you going
> to do to implement any of these ideas?"

I am doing 2 things:

1. continuing to develop the idea of the "perl" memory model (uniprocess) and
the Perl memory model (semantically, admits concurrency). See Sub::Genius.

2. approaching concurrency from the shared memory perspective by exploring various
ideas in order to determine how OpenMP can be most naturally leveraged on an SMP
machine. See OpenMP::Environment and Alien::OpenMP.

I'd prefer to not sour any potential for us to work together because I am additionally
interested in understanding what hidden opportunities exist for exploiting shared
memory IPC among fork'd perl processes. Seems you have quite a list of modules that
are in this area, which is great.

I hope that's sufficient to satisfy your question. Seems the my opinion that emulated
threads are "fake" is offensive to some, but it's not. It's just the only way I
know to clearly differentiate "real" shared memory threading and IPC (among fork'd
processes) from thread "emulation".

>
>
> > So as long as it's TIMTOWTDI, I think it's a fabulous idea. Let me
> > know where to sign up! (#concurrency on irc.perl might be a cool
> > idea, too; but maybe after).
> >
>
> Mailing lists usually start when a cc: field gets too big (that's literally
> how p5p started back in the day), so I would suggest you start with asking
> who wants to join.

I was not the originator of this request, but your advice seems legitimate. If
this is pursued, I'll join that email list immediately.

Cheers,
Brett

>
> Leon

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
2021-7-29 14:12 Oodler 577 <oodler577@sdf-eu.org>:

My personal interest is shared memory.
>

Does this mean Perl implements Java Thread? (Java uses native thread).
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
* Yuki Kimoto <kimoto.yuki@gmail.com> [2021-07-31 14:34:14 +0900]:

> 2021-7-29 14:12 Oodler 577 <oodler577@sdf-eu.org>:
>
> My personal interest is shared memory.
> >
>
> Does this mean Perl implements Java Thread? (Java uses native thread).

I don't know what java does. What I mean is what pthreads does.

Brett

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
2021-8-1 1:10 Oodler 577 <oodler577@sdf-eu.org> wrote:

> * Yuki Kimoto <kimoto.yuki@gmail.com> [2021-07-31 14:34:14 +0900]:
>
> > 2021-7-29 14:12 Oodler 577 <oodler577@sdf-eu.org>:
> >
> > My personal interest is shared memory.
> > >
> >
> > Does this mean Perl implements Java Thread? (Java uses native thread).
>
> I don't know what java does. What I mean is what pthreads does.
>
>
I understand that the concurrency you want to discuss is features of
pthreads.
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
perl5-porters:

Thank you everyone for your thoughts. :-)


On 7/24/21 10:48 PM, Oodler 577 via perl5-porters wrote:> * David
Christensen <dpchrist@holgerdanske.com> [2021-07-24 16:08:58 -0700]:

>> Whatever is done, I have been wanting a Perl concurrency mailing list
>> for many years.

> Regarding the discussion of "threads" - I'd love to have one.

I'm fine talking about threading, concurrency, etc., here. It is useful
to have archives, so a cc: model does not appeal.


On 7/25/21 4:10 AM, Leon Timmermans wrote:
> On Sun, Jul 25, 2021 at 1:09 AM David Christensen wrote:
>> For example, I have discovered that threads is not fully compatible
>> with Data::Dumper and Capture::Tiny.
>
> The former sounds like a bug.

https://github.com/Perl/perl5/issues/19014


> The latter deals with a process-global resource (standard IO), so
> will inherently have some funkiness.


The following Capture::Tiny documentation led directly to my previous
"self-fulfilling prophecy" statement:

2021-08-01 15:51:56 dpchrist@dipsy ~
$ perldoc Capture::Tiny | head -n 262 | tail -n 4
Using threads
Filehandles are global. Mixing up I/O and captures in different threads
without coordination is going to cause problems. Besides, threads are
officially discouraged.


Threading was a core Perl feature. CPAN modules were supposed to
support threading. Then threads were declared "officially discouraged".
What was supposed to replace threads?


Now my choices are 1) make Capture::Tiny thread-safe, or 2) write a
sawed-off thread-safe replacement. Madness:

http://winestockwebdesign.com/Essays/Lisp_Curse.html =~ s/lisp/perl/ig


> IMO what we need is to research other threading models on top of the
> primitives that we have (and if needed extend those primitives).
> threads::lite was my first attempt at that, though I've started a
> successor.


AIUI threads and threads::shared were the canonical Perl threading
primitives, as demonstrated by their inclusion in the Camel book. I am
aware of the following documentation, which describes the threading
model they implement:

"Programming Perl" [1], pages 1035-1036, 1078.

https://metacpan.org/pod/Thread

https://metacpan.org/pod/threads

https://metacpan.org/pod/threads::shared

https://metacpan.org/dist/perl/view/pod/perlthrtut.pod


"Network Programming with Perl" [2] identifies additional primitives and
non-primitives that can relate to concurrency.


On 7/25/21 8:26 AM, Oodler 577 via perl5-porters wrote:
> The ideas of "practical" concurrency is way more important to
> perl/Perl's future than virtually any other issue.


Which feature is most important is debatable.


I would put "Conceptual Integrity" and "Programming Systems Product" at
the top of the list, per Brooks [3].


AIUI threads were pushed to the forefront ~20 years ago, when multi-core
and hyper-threading microprocessors became commodity items. As always,
user expectations have risen since then. And, as always, developers are
expected to create software that can make full use of the latest
hardware. So, if Perl wants developers, Perl must give developers the
tools they need to meet user expectations.


But, threading is just one way to achieve concurrency on a single
computer. The traditional Unix way is fork/ exec. I can simulate
concurrency in a single thread by invoking short, non-blocking
subroutines in a tight loop (e.g. polling, asynchronous I/O, select),
but that approach is brittle; my application becomes a scheduler.
Perhaps I could write a Perl program, launch it into the background with
a 1-argument system() or qx(), and communicate with it over non-blocking
pipes or sockets. Are there any other core Perl mechanisms to achieve
concurrency within a single computer?


Are there any core Perl mechanisms to achieve real concurrency on a
network of computers?


> ... openmp ...

https://www.openmp.org/

https://www.mpi-forum.org/


Perl modules/ distributions for these could be useful.


> Off the top of my head there are many topics ripe for discussion:
>
> * ithreads
> * forking based things
> * async
> * "real" threads via OpenMP/pthreads bindings
> * perl vs Perl memory models
> * atomicity/sequential consistency


I'm happy to discuss any or all of them. :-)


On 7/28/21 8:26 AM, Ovid wrote:
> Give me:
>
> - Concurrency
> - OOP
> - Signatures
> - Some way of defining enforceable types
>
> With that, Perl can come out of the gate swinging.


I would like:

- Conceptual Integrity

- Programming Systems Product -- functional specification, design/
construction specification, test/ validation specification, etc., with
everything documented and under configuration management

- Multi-paradigm -- imperative, functional, object-oriented,
declarative, meta-programming (includes signatures and types)

- Multi-Platform -- add Android and iOS

- Memory safe/ garbage collected

- Secure

- Concurrent/ Distributed/ Networked

- Macros

- Programs can be compiled and statically linked into stand-alone
executeables


On 7/28/21 10:32 AM, shmem wrote:> Last time I looked there was MCE
which somehow looks meaningful.

https://metacpan.org/dist/MCE/view/lib/MCE.pod

I saw MCE. And POE. And Coro. And PDL. I put my effort into threads
and threads::shared years ago (pre-discouraged) because they looked like
the foundation of threading in Perl, they were the most similar to my
previous C/ assembly experiences, and I thought I could build useful
stuff with them. These reasons have proven to be mostly correct. The
problems I have now are dealing with non-thread-safe code throughout the
rest of Perl and the knowledge that threads are on the chopping block.


On 7/28/21 11:05 AM, Oodler 577 via perl5-porters wrote:
> What we need is a door into the sharing of memory; if not among
> threads (not my goal), surely amoung fork'd processes. Coupled with
> atomic synchronization primatives (which we have in some form via
> sysopen), this would provide us a path to utilize forks+shared memory.


I read about shared memory on Unix via C years ago, but have not needed
or used it. STFW I see existing modules/ distributions that do shared
memory. You don't see anything you like?

https://metacpan.org/search?q=shared+memory


On 7/28/21 8:59 PM, Yuki Kimoto wrote:
> The word "concurrency" is always ambiguous when people talk about
> "concurrency".


https://en.wikipedia.org/wiki/Concurrency_(computer_science)


> I hear the this conversation "Perl doesn't have concurrency, so Perl
> can't use CPUs in parallel"
>
> But, I know the pre-fork model Perl web applications are using CPUs in
> parallel.
>
> I think we need to properly classify concurrency(fork, thread, I/O,
> CPU(OpenMP), GPU, coroutine, async/await syntax) before we say we want
> to add concurrency.


Perl has several forms of concurrency. Unfortunately, a
high-visibility, core form -- threading -- has not worked out and is now
unmaintained.


On 7/28/21 10:12 PM, Oodler 577 wrote:
> Typically, OpenMP is accomplished at low level with pthreads.


AIUI POSIX Threads (pthreads) are not supported on all of the platforms
that support Perl. So, Perl was required invented its own
multi-platform threading model.


I suspect OpenMP will similarly lose to multi-platform. Can OpenMP be
put into a Perl module that works on the relevant subset of platforms?


For that matter, can POSIX Threads be put into a Perl module that works
on the relevant subset of platforms?


Have these been tried already (see next)?


On 7/29/21 10:34 AM, Leon Timmermans wrote:
> In practice, all ideas have either been already done, or are very
> difficult (or even impossible) to do.


Please let us know if you see the discussion headed that way.


On 7/29/21 10:34 AM, Leon Timmermans wrote:
> I agree [concurrency is] important, that's why I'm actually working on
> the issue. To be precise, an ithreads based (so can actually use
> multiple processors) continuation passing style (same model Go uses
> for its channels) module.


https://en.wikipedia.org/wiki/Continuation-passing_style


STFW again, I see existing modules/ distributions with continuations.
You do not see anything you like?

https://metacpan.org/search?size=20&q=continuation


Can continuations be abstracted out, become a Perl primitive, and used
throughout?


On 7/29/21 10:47 AM, Oodler 577 wrote:

> I am doing 2 things:
>
> 1. continuing to develop the idea of the "perl" memory model
> (uniprocess) and the Perl memory model (semantically, admits
> concurrency). See Sub::Genius.
>
> 2. approaching concurrency from the shared memory perspective by
> exploring various ideas in order to determine how OpenMP can be most
> naturally leveraged on an SMP machine. See OpenMP::Environment and
> Alien::OpenMP.


https://metacpan.org/pod/Sub::Genius

https://metacpan.org/pod/OpenMP::Environment

https://metacpan.org/pod/Alien::OpenMP


I have been searching for a general model of concurrency for many years.
Flow-based programming (FBP) has caught my interest:

https://en.wikipedia.org/wiki/Flow-based_programming


STFW I did not see anything I liked:

https://metacpan.org/search?q=flow

https://metacpan.org/search?q=fbp


I have built a simplified FBP library in Perl using threads and a
re-write of Thread::Queue (with multiple readers and writers, and
coordinated open and close). It can run FBP programs concurrently on
multi-core and/or hyper-threaded processors. It should be able to run a
FBP program concurrently on multi-processor computers (when I have such
a machine for testing). I am now researching extensions so that it can
run a FBP program concurrently on a network of multiple computers.


David



References:

[1] Tom Christiansen, et al, 2012, "Programming Perl", 4 e,
https://www.oreilly.com/library/view/programming-perl-4th/9781449321451/

[2] Lincoln D. Stein, 2000, "Network Programming with Perl",
https://www.oreilly.com/library/view/network-programming-with/0201615711/

[3] Frederick P. Brooks, 1996, "Mythical Man-Month, The: Essays on
Software Engineering, Anniversary Edition," 2 e.,
https://www.pearson.com/us/higher-education/program/Brooks-Mythical-Man-Month-The-Essays-on-Software-Engineering-Anniversary-Edition-2nd-Edition/PGM172844.html
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
> On 7/29/21 10:34 AM, Leon Timmermans wrote:
> > I agree [concurrency is] important, that's why I'm actually working on
> > the issue. To be precise, an ithreads based (so can actually use
> > multiple processors) continuation passing style (same model Go uses
> > for its channels) module.
>
>
> https://en.wikipedia.org/wiki/Continuation-passing_style
>
>
> STFW again, I see existing modules/ distributions with continuations.
> You do not see anything you like?
>
> https://metacpan.org/search?size=20&q=continuation
>
>
> Can continuations be abstracted out, become a Perl primitive, and used
> throughout?
>

Sorry, I meant CSP (Communicating sequential processes) not CPS
(continuation passing style)

Leon
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On 8/2/21 12:05 PM, Leon Timmermans wrote:
>> On 7/29/21 10:34 AM, Leon Timmermans wrote:
>> > I agree [concurrency is] important, that's why I'm actually working on
>> > the issue. To be precise, an ithreads based (so can actually use
>> > multiple processors) continuation passing style (same model Go uses
>> > for its channels) module.

> Sorry, I meant CSP (Communicating sequential processes) not CPS
> (continuation passing style)


CSP is a proven model for concurrency.


AIUI CSP is the raison d'être of the Go programming language, which has
become the dominant concurrent programming language (and ahead of Perl
in general):

https://www.tiobe.com/tiobe-index/


This tutorial provides a taste of goroutines and channels:

https://golangbot.com/channels/


How are your CSP channels implemented in Perl?


Have you thought ahead to distributed/ network programming?


David
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
2021-8-3 6:12 David Christensen <dpchrist@holgerdanske.com> wrote:

> On 8/2/21 12:05 PM, Leon Timmermans wrote:
> >> On 7/29/21 10:34 AM, Leon Timmermans wrote:
> >> > I agree [concurrency is] important, that's why I'm actually working
> on
> >> > the issue. To be precise, an ithreads based (so can actually use
> >> > multiple processors) continuation passing style (same model Go uses
> >> > for its channels) module.
>
> > Sorry, I meant CSP (Communicating sequential processes) not CPS
> > (continuation passing style)
>
>
> CSP is a proven model for concurrency.
>
>
> AIUI CSP is the raison d'être of the Go programming language, which has
> become the dominant concurrent programming language (and ahead of Perl
> in general):
>
> https://www.tiobe.com/tiobe-index/
>
>
> This tutorial provides a taste of goroutines and channels:
>
> https://golangbot.com/channels/
>
>
> How are your CSP channels implemented in Perl?
>
>
> Have you thought ahead to distributed/ network programming?
>
>
> David
>

Generally Speaking, about concurrency like goroutines and channels, it's
difficult if it isn't designed from the beginning of the language.

If you want to implement it, see SPVM at once. SPVM is yet before version
1.0.

https://metacpan.org/pod/SPVM

You can also try out experiments on concurrency implementation on SPVM.
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On 8/2/21 7:20 PM, Yuki Kimoto wrote:
> 2021-8-3 6:12 David Christensen <dpchrist@holgerdanske.com> wrote:

>> CSP is a proven model for concurrency.

> Generally Speaking, about concurrency like goroutines and channels, it's
> difficult if it isn't designed from the beginning of the language.
>
> If you want to implement it, see SPVM at once. SPVM is yet before version
> 1.0.
>
> https://metacpan.org/pod/SPVM
>
> You can also try out experiments on concurrency implementation on SPVM.


Static Perl Virtual Machine:

https://yuki-kimoto.github.io/spvmdoc-public/


That looks like you have invested a lot of effort.


At a glance, SPVM looks like an alternative to Perl XS (?).


Does SPVM support concurrency in any form(s)?


David
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
2021-8-3 12:05 David Christensen <dpchrist@holgerdanske.com> wrote:

> On 8/2/21 7:20 PM, Yuki Kimoto wrote:
> > 2021-8-3 6:12 David Christensen <dpchrist@holgerdanske.com> wrote:
>
> >> CSP is a proven model for concurrency.
>
> > Generally Speaking, about concurrency like goroutines and channels, it's
> > difficult if it isn't designed from the beginning of the language.
> >
> > If you want to implement it, see SPVM at once. SPVM is yet before version
> > 1.0.
> >
> > https://metacpan.org/pod/SPVM
> >
> > You can also try out experiments on concurrency implementation on SPVM.
>
>
> Static Perl Virtual Machine:
>
> https://yuki-kimoto.github.io/spvmdoc-public/
>
>
> That looks like you have invested a lot of effort.
>
>
> At a glance, SPVM looks like an alternative to Perl XS (?).
>
>
> Does SPVM support concurrency in any form(s)?
>
>
> David
>

I'm sorry for introducing my personal development.

>At a glance, SPVM looks like an alternative to Perl XS

Yes. SPVM is a language transpiler to C.

> Does SPVM support concurrency in any form(s)?

First concurrency support is easy to implement C openmp binding.

https://github.com/yuki-kimoto/SPVM/tree/master/examples/native/openmp/lib

Second is concurrency support is easy to implement cuda/GUP binding.

https://github.com/yuki-kimoto/SPVM/tree/master/examples/native/cuda_add

Third is the ability to implement pthreads and goroutine.

SPVM has a feature coping runtime using new_env api.

https://metacpan.org/dist/SPVM/view/lib/SPVM/Document/NativeAPI.pm#new_env

SPVM runtime is very small. I think when spawning threads, the small
runtime is important for the performance.

If goroutine can be implemented by SPVM module, new_env specification is
important.

Since it is before release, I can also think about data structures and
specifications that allow goroutine or pthread.
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On 8/2/21 9:14 PM, Yuki Kimoto wrote:
> 2021-8-3 12:05 David Christensen <dpchrist@holgerdanske.com> wrote:
>> On 8/2/21 7:20 PM, Yuki Kimoto wrote:

>>> https://metacpan.org/pod/SPVM

> I'm sorry for introducing my personal development.


Thank you for introducing SPVM. :-)


>> At a glance, SPVM looks like an alternative to Perl XS
>
> Yes. SPVM is a language transpiler to C.


Okay.


>> Does SPVM support concurrency in any form(s)?
>
> First concurrency support is easy to implement C openmp binding.
>
> https://github.com/yuki-kimoto/SPVM/tree/master/examples/native/openmp/lib

<snip>


I would like to understand the first concurrency example, and will hold
off on the second example and remainder of your reply for now. Please
bring the removed ideas back into the conversation if and when it makes
sense.


Looking at:

https://github.com/yuki-kimoto/SPVM/tree/master/examples/native/openmp


I see:

- lib/MyOpenMP.c => contains C source code:

- int32_t SPNATIVE__MyOpenMP__sum_vec_int(...) {...} => defines a
SPVM native function in the package "MyOpenMP" with function name
"sum_vec_int"

- #pragma omp parallel for => enables OpenMP parallelization of the
following "for" loop

- lib/MyOpenMP.spvm => contains SPVM source code:

- package MyOpenMP => sets the package namespace

- sub test : void () {...} => defines the package "MyOpenMP" function
"test"

- lib/MyOpenMP.conf => contains SPVM transpiler configuration settings

- openmp.pl => contains Perl source code:

- use SPVM 'MyOpenMP' => imports the package "MyOpenMP" created by
the SPVM transpiler (presumably via EUMM or MB)

- MyOpenMP->test => invokes the class "MyOpenMP" method "test"


So, SPVM deals with several intermediate layers between OpenMP
concurrency and the Perl script:

- pragmatized C "for" loop

- C function "SPNATIVE__MyOpenMP__sum_vec_int"

- SPVM function "MyOpenMP::sum_vec_int"

- SPVM function "MyOpenMP::test"


Is there a way to eliminate one or more intermediate layers?

- Calling MyOpenMP::sum_vec_int() from Perl?

- Putting "#pragma omp parallel for" above a Perl "for" loop?


David
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
2021-8-3 14:40 David Christensen <dpchrist@holgerdanske.com>:

>
>
> Is there a way to eliminate one or more intermediate layers?
>
> - Calling MyOpenMP::sum_vec_int() from Perl?
>

Yes. You can call this method directly, and you can release this module to
CPAN.


> - Putting "#pragma omp parallel for" above a Perl "for" loop?
>

a Perl "for" loop maybe means a SPVM "for" loop.

No, SPVM doesn't support openmp pragma.
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On Mon, Aug 02, 2021 at 10:39:55AM -0700, David Christensen wrote:
> Then threads were declared "officially discouraged". What was
> supposed to replace threads?

I think "discouraging" threads was a mistake and we should undo it.
Since that change, people have always been confusing "discourage" with
"deprecate".

The intent of the discouragement was more to warn people that the ithreads
threading model may not be what they were expecting (especially that data
is not shared by default).

As long as people are aware of the strengths and weaknesses of ithreads,
I see no reason why people should not continue to use it.

Note that although Jerry has given up unofficial ownership of the threads
and threads::shared modules, these were always actually owned by p5p and
will continue as before to be maintained. And in particular, the threads
module is just just a thin veneer to allow access to the underlying
ithreads in the perl core - and ithreads has has always been a core
responsibility.

For certain types of work, ithreads will give you full access to the
parallelism provided by multiple cores. The implementation within the core
is mature and seems mosty free of bugs (I don't recall having to track
down a race condition for a long time now).




--
"Foul and greedy Dwarf - you have eaten the last candle."
-- "Hordes of the Things", BBC Radio.
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On Tue, Aug 03, 2021 at 01:42:41PM +0100, Dave Mitchell wrote:
> On Mon, Aug 02, 2021 at 10:39:55AM -0700, David Christensen wrote:
> > Then threads were declared "officially discouraged". What was
> > supposed to replace threads?
>
> I think "discouraging" threads was a mistake and we should undo it.
> Since that change, people have always been confusing "discourage" with
> "deprecate".
>
> The intent of the discouragement was more to warn people that the ithreads
> threading model may not be what they were expecting (especially that data
> is not shared by default).
>
> As long as people are aware of the strengths and weaknesses of ithreads,
> I see no reason why people should not continue to use it.

> For certain types of work, ithreads will give you full access to the
> parallelism provided by multiple cores. The implementation within the core
> is mature and seems mosty free of bugs (I don't recall having to track
> down a race condition for a long time now).

Unlike Python, where they are still working on implementing MULTIPLICY:
https://www.python.org/dev/peps/pep-0554/

(This is not meant as a cheap shot. Far from it. It's interesting that
the history of the GIL, and Guido explicitly embracing threading early
by consciously taking a big hammer "mutex" solution, means that Python
has taken a completely different direction. As I understand it

1) the GIL means that there is no *concept* of "per interpreter", hence
massive amounts of things really are in global C variables, and have
to migrate to "one per interpreter"
2) the lack of encapsulated interpreter state meant that there was never
a "allocate, create, use, destroy, release" cycle for the interpreter
state, meaning that code does not *exist* to free some things. It's
assumed to be taken care of by process exit

These choices are quite reasonable. It's like PERL_DESTRUCT_LEVEL=0,
hardcoded, and remove all our teardown code that only runs for level 2.

Except that they never had level 2, so now they need to write all that
code. Which we've had for 20 years.)

Nicholas Clark
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On Mon, 2 Aug 2021 14:12:18 -0700
David Christensen <dpchrist@holgerdanske.com> wrote:

> Have you thought ahead to distributed/ network programming?

We discussed it at great length in Amsterdam, 2019, yes.


I have so far avoided wading into this "concurrency" chat, but at this
point I sortof feel I must. I'm not going to specifically respond to
individual points, but rather address the entire tone of the thread as
a whole.

The thread started with two points, one about Perl's (perceived) lack
of support for "concurrency", and a thought about starting a mailing
list about it.


## On Perl's Concurrency

Yuki Kimoto made a good summary here; I shall quote:

> I think we need to properly classify concurrency(fork, thread, I/O,
> CPU(OpenMP), GPU, coroutine, async/await syntax) before we say we want
> to add concurrency.

That list suggests the usual way I like to stare at these things - are
we talking concurrency of communication, or concurrency of computation?
I.e. are the tasks we're performing IO-bound or CPU-bound?

If the former, then I really don't buy the statement that Perl is
lacking in this area. We have tonnes of good stuff - as well as a
variety of "older" event systems, we also have a growing collection of
Future-based asynchronous code management. For example, if you want to
fetch a bunch of HTTP URLs by making 10 concurrent connections at once,
you can (eliding the `use` statements for brevity):

my @urls = (lots of URLs here);

my $http = Net::Async::HTTP->new;
IO::Async::Loop->add( $http );

my @responses = await Future::Utils::fmap {
$http->GET( $_ )
} foreach => \@urls, concurrent => 10;

Similarly any other sorts of "large amounts of concurrent IO" problems
are equally simple with a lot of these modern solutions.

Or perhaps you meant the latter kind of problem; those CPU-bound ones.
Thing is a whole heap of those are equally trivial with this sort of
system. Perhaps we want to find which English word gives us the lowest
sha256 sum when concatenated with some payload data, by splitting the
task across 10 CPU cores (again eliding `use` statements):

my @words = map { chomp $_; $_ }
path("/usr/share/dict/words")->lines;

my $payload = (much data here);

my $result = List::UtilsBy::minstr_by { $_->[1] }
Parallel::Map::pmap_scalar {
[ $_, Crypt::Digest::SHA256::sha256($payload . $_) ]
} foreach => \@words, forks => 10;

my $best_word = $result->[0];


It's hard to see what is fundamentally missing from the language here.
Perhaps the async/await keywords could be core syntax. Or perhaps some
of the modules involved could be shipped by core. But is that
necessary? After all, core doesn't ship a CSV parser, or a database
connector, or an HTML template system, and yet people don't say Perl is
lacking in these, they just grab them from CPAN.

In terms of the innermost details of implementation, it's perhaps
possible to find more performant ways that the insides can be
implemented, perhaps by using some shared memory structure instead of
the marshalling overhead of using some pipes, but overall that doesn't
fundamentally change the shape of the solution, nor the way the code is
written, it just makes it burn slightly fewer CPU cycles while it runs.
(I believe there are various projects underway looking at exactly this
problem, by the way).


Overall though I really don't accept the statement that "Perl can't do
concurrency". I think I demonstrate above that it clearly can do both
concurrency-of-communication and concurrency-of-computation.


## On Needing A Mailing List

If you really feel it necessary, sure go set one up. I don't feel that
a "perl + concurrency" mailing list is a fundamentally different beast
to a "perl + databases" or "perl + electronics" list. Here's some stuff
we could do in Perl, via the help of some CPAN modules, and we can
discuss that subject.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
On Mon, Aug 2, 2021 at 11:12 PM David Christensen <dpchrist@holgerdanske.com>
wrote:

> CSP is a proven model for concurrency.
>
>
> AIUI CSP is the raison d'être of the Go programming language, which has
> become the dominant concurrent programming language (and ahead of Perl
> in general):
>
> https://www.tiobe.com/tiobe-index/
>
>
> This tutorial provides a taste of goroutines and channels:
>
> https://golangbot.com/channels/
>

Yeah, that's the one :-)


> How are your CSP channels implemented in Perl?
>

On top of ithreads, but without threads.pm


> Have you thought ahead to distributed/ network programming?
>

I have thought about it, and decided it's well outside of scope for this
project for now.

Leon
Re: concurrency list (was Re: Relinquishing Maintenance of Core Modules) [ In reply to ]
* Nicholas Clark <nick@ccl4.org> [2021-08-03 13:01:48 +0000]:

> On Tue, Aug 03, 2021 at 01:42:41PM +0100, Dave Mitchell wrote:
> > On Mon, Aug 02, 2021 at 10:39:55AM -0700, David Christensen wrote:
> > > Then threads were declared "officially discouraged". What was
> > > supposed to replace threads?
> >
> > I think "discouraging" threads was a mistake and we should undo it.
> > Since that change, people have always been confusing "discourage" with
> > "deprecate".
> >
> > The intent of the discouragement was more to warn people that the ithreads
> > threading model may not be what they were expecting (especially that data
> > is not shared by default).
> >
> > As long as people are aware of the strengths and weaknesses of ithreads,
> > I see no reason why people should not continue to use it.
>
> > For certain types of work, ithreads will give you full access to the
> > parallelism provided by multiple cores. The implementation within the core
> > is mature and seems mosty free of bugs (I don't recall having to track
> > down a race condition for a long time now).
>
> Unlike Python, where they are still working on implementing MULTIPLICY:
> https://www.python.org/dev/peps/pep-0554/
>
> (This is not meant as a cheap shot. Far from it. It's interesting that
> the history of the GIL, and Guido explicitly embracing threading early
> by consciously taking a big hammer "mutex" solution, means that Python
> has taken a completely different direction. As I understand it
>
> 1) the GIL means that there is no *concept* of "per interpreter", hence
> massive amounts of things really are in global C variables, and have
> to migrate to "one per interpreter"
> 2) the lack of encapsulated interpreter state meant that there was never
> a "allocate, create, use, destroy, release" cycle for the interpreter
> state, meaning that code does not *exist* to free some things. It's
> assumed to be taken care of by process exit
>
> These choices are quite reasonable. It's like PERL_DESTRUCT_LEVEL=0,
> hardcoded, and remove all our teardown code that only runs for level 2.
>
> Except that they never had level 2, so now they need to write all that
> code. Which we've had for 20 years.)
>
> Nicholas Clark

Understanding that "perl" is a uniprocess and that Perl tempts us into
wanting concurrency is a crucial point to blast through the cognative
dissonnance, reconcile what we have versus what we want, and then move
forward in various approaches fully and openly. This was the main point
that I wanted to make with my conference talk on sequential consistency,
and why it's a valuable concept for undertanding the true state of things.

It will save us from spending too much time on things that fundamentally
don't make any sense.

Cheers,
Brett

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native