pharo-users@lists.pharo.org

Any question about pharo is welcome

View all threads

Pharo concurrency: select on socket or file IO

V
vinref@gmail.com
Thu, Jul 22, 2021 6:57 AM

Can the Pharo VM or a library do a “select” on a collection of processes waiting on a socket or file IO? Something like https://man7.org/linux/man-pages/man2/select.2.html, or https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select.

Say I have a bunch of forked processes and some will get blocked waiting for IO. I would put the blocked connections/processes in a collection and non-blocked processes can continue to do useful work. At some appropriate I would do a select on the blocked processes and resume those that are done.

Vince

Can the Pharo VM or a library do a “select” on a collection of processes waiting on a socket or file IO? Something like https://man7.org/linux/man-pages/man2/select.2.html, or https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select. Say I have a bunch of forked processes and some will get blocked waiting for IO. I would put the blocked connections/processes in a collection and non-blocked processes can continue to do useful work. At some appropriate I would do a select on the blocked processes and resume those that are done. Vince
GF
giorgio ferraris
Thu, Jul 22, 2021 8:27 AM

Hi, Vince,

I don't know exactly Pharo, but when you fork a process, it becomes
an independent thread of work. So in that process you can send your
async call and wait for a response and then do the work. All inside the
forked process.
It's the smallalk's scheduler that will take care of passing control to
other available (green) threads
So it's not clear from me what you need. If you have many forked processes,
each one will do is work up to the end. No need to resume it from outside.

hth
ciao

giorgio

On Thu, Jul 22, 2021 at 8:57 AM vinref@gmail.com wrote:

Can the Pharo VM or a library do a “select” on a collection of processes
waiting on a socket or file IO? Something like
https://man7.org/linux/man-pages/man2/select.2.html, or
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
.

Say I have a bunch of forked processes and some will get blocked waiting
for IO. I would put the blocked connections/processes in a collection and
non-blocked processes can continue to do useful work. At some appropriate I
would do a select on the blocked processes and resume those that are done.

Vince

Hi, Vince, I don't know exactly Pharo, but when you fork a process, it becomes an independent thread of work. So in that process you can send your async call and wait for a response and then do the work. All inside the forked process. It's the smallalk's scheduler that will take care of passing control to other available (green) threads So it's not clear from me what you need. If you have many forked processes, each one will do is work up to the end. No need to resume it from outside. hth ciao giorgio On Thu, Jul 22, 2021 at 8:57 AM <vinref@gmail.com> wrote: > Can the Pharo VM or a library do a “select” on a collection of processes > waiting on a socket or file IO? Something like > https://man7.org/linux/man-pages/man2/select.2.html, or > https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select > . > > Say I have a bunch of forked processes and some will get blocked waiting > for IO. I would put the blocked connections/processes in a collection and > non-blocked processes can continue to do useful work. At some appropriate I > would do a select on the blocked processes and resume those that are done. > > Vince >
T
tesonep@gmail.com
Thu, Jul 22, 2021 10:10 AM

Hi,
Socket implementation in the VM already handles Async IO operations.
The execution model in Pharo is intended to have many concurrent green
threads (they are not OS threads, they are handled by Pharo VM). These
green threads are called processes in Pharo.
Pharo Green threads are quite cheap to create and use, and the context
switch of them is quite cheap also.
The programming model of Pharo is intended to have many concurrent green
threads, without caring if they block in tIO operations.
These block green threads are handled by the VM and the VM continue
executing useful code.
For orchestrating and communication between the green threads you can use
low-level synchronization as semaphores and mutex, but also there is a rich
library (Taskit) for using Asynchronous tasks, Callables and Futures.

Cheers,
Pablo

On Thu, Jul 22, 2021 at 8:57 AM vinref@gmail.com wrote:

Can the Pharo VM or a library do a “select” on a collection of processes
waiting on a socket or file IO? Something like
https://man7.org/linux/man-pages/man2/select.2.html, or
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
.

Say I have a bunch of forked processes and some will get blocked waiting
for IO. I would put the blocked connections/processes in a collection and
non-blocked processes can continue to do useful work. At some appropriate I
would do a select on the blocked processes and resume those that are done.

Vince

--
Pablo Tesone.
tesonep@gmail.com

Hi, Socket implementation in the VM already handles Async IO operations. The execution model in Pharo is intended to have many concurrent green threads (they are not OS threads, they are handled by Pharo VM). These green threads are called processes in Pharo. Pharo Green threads are quite cheap to create and use, and the context switch of them is quite cheap also. The programming model of Pharo is intended to have many concurrent green threads, without caring if they block in tIO operations. These block green threads are handled by the VM and the VM continue executing useful code. For orchestrating and communication between the green threads you can use low-level synchronization as semaphores and mutex, but also there is a rich library (Taskit) for using Asynchronous tasks, Callables and Futures. Cheers, Pablo On Thu, Jul 22, 2021 at 8:57 AM <vinref@gmail.com> wrote: > Can the Pharo VM or a library do a “select” on a collection of processes > waiting on a socket or file IO? Something like > https://man7.org/linux/man-pages/man2/select.2.html, or > https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select > . > > Say I have a bunch of forked processes and some will get blocked waiting > for IO. I would put the blocked connections/processes in a collection and > non-blocked processes can continue to do useful work. At some appropriate I > would do a select on the blocked processes and resume those that are done. > > Vince > -- Pablo Tesone. tesonep@gmail.com
V
vinref@gmail.com
Thu, Jul 22, 2021 10:38 PM

TaskIt is fantastic! I never realised this existed at all. This is exactly what I need.

Thanks Pablo

TaskIt is fantastic! I never realised this existed at all. This is exactly what I need. Thanks Pablo