From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14831 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: broadcast fd Date: Fri, 18 Oct 2019 21:44:58 -0400 Message-ID: <20191019014458.GB16318@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="191314"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14847-gllmg-musl=m.gmane.org@lists.openwall.com Sat Oct 19 03:45:12 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1iLdns-000nfU-MK for gllmg-musl@m.gmane.org; Sat, 19 Oct 2019 03:45:12 +0200 Original-Received: (qmail 26287 invoked by uid 550); 19 Oct 2019 01:45:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 26269 invoked from network); 19 Oct 2019 01:45:09 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14831 Archived-At: 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