guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The Shepherd on Fibers


From: Ludovic Courtès
Subject: Re: The Shepherd on Fibers
Date: Tue, 29 Mar 2022 13:44:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Hi!

"pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de> skribis:

> On Wed, Mar 23, 2022 at 11:36:30PM +0100, Ludovic Courtès wrote:
>> Fibers is used in a single-threaded fashion, which is the main
>> constraint for shepherd since it forks.  That also means that fibers
>> cannot be preempted, so it’s fully cooperative scheduling.
>
> To understand what you mean, I needed to read shepherd commit
> 934204fbd158aa9fbd42914b89aa960f99eef125
>
> +      ;; Run Fibers in such a way that it does not create any POSIX thread,
> +      ;; because POSIX threads and 'fork' cannot be used together
>
> So shepherd service authors still cannot write blocking code but need
> to yield?

Yes.  Technically though, “yielding” is transparent: any time you do I/O
(‘get-bytevector-n’, etc.) or call ‘sleep’ (specifically the one
provided by Fibers), your code potentially yields, letting Fibers
schedule some other activity.

What that means in practice is that starting services, waiting for PID
files, serving clients—all this happens concurrently.

It *is* possible to write service code that would block everything, but
with little or no effort, you can make it cooperate with the scheduler.

HTH,
Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]