mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: broadcast fd
Date: Fri, 18 Oct 2019 21:44:58 -0400	[thread overview]
Message-ID: <20191019014458.GB16318@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAHSMefiLDxRJMFstWOysSmApqZeX296e1+uxhNVzL7SXjoLQdw@mail.gmail.com>

On Tue, Oct 15, 2019 at 10:04:47AM -0700, Leonid Shamis wrote:
> Hi Folks,
> 
> TLDR:
> 
> How do I broadcast a notification across processes, without a broker?
> 
> Long story:
> 
> I'm building an ipc-over-shm library with some unusual restrictions:
> * There are multiple channels of communication (each in it's own shm).
> * Each channel contains non-consumable resources (not a message queue).
> * Multiple processes can produce resources on the same channel.
> * Multiple consumers can access/use the resources.
> * Resources are versioned and (some) old versions are kept available.
> * Spurious wakeups are ok, but missing notifications (starvation) is not.
> * The library must be robust (in the mutex sense), meaning a process may
> crash without taking down the rest of the system.
> 
> I'm trying to figure out how to notify a process that a new resource is
> available on a channel.
> 
> Right now, my library puts (the equivalent of) a robust conditional
> variable in shared memory, for each channel.
> Each process must spawn a thread per-channel, just to await the cv
> broadcast.
> 
> I'd ideally like to use a single thread with something like an epoll.
> For this, I'd need to get an fd (maybe eventfd) per channel into the hands
> of every process that wants to connect to a channel.
> fds, as I understand, cannot be shared via shared memory, only pipes, but
> I'm required to be brokerless.
> futex_fd are very deprecated.
> 
> Am I missing another approach?

If you want the events associated with the shared memory objects, and
you have file descriptors for these objects (they're POSIX shm or
hand-rolled tmpfs shm, as opposed to sysvipc), perhaps there's a way
to convey the event availability through the fd. For example is there
a way you could use inotify to do it?

Otherwise I think you already have the best way. Keep in mind the
cv-waiting thread can be made tiny if you use a minimal stack size,
run with signals blocked, and just have it convert cv events to
self-pipe/eventfd/etc.

Rich


      reply	other threads:[~2019-10-19  1:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 17:04 Leonid Shamis
2019-10-19  1:44 ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191019014458.GB16318@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).