tevent in multithreaded programs

Volker Lendecke Volker.Lendecke at SerNet.DE
Sat Jan 31 06:03:54 MST 2015


On Fri, Jan 30, 2015 at 05:37:39PM -0500, Simo wrote:
> On Fri, 2015-01-30 at 21:16 +0100, Volker Lendecke wrote:
> > On Fri, Jan 30, 2015 at 03:03:25PM -0500, Simo wrote:
> > > FWIW, I had a chat with Jeff on IRC and suggest him to use the same
> > > approach we use to handle signals.
> > > 
> > > Namely create a sentinel pipe and add it as fd event, also create a main
> > > list that is accessed via mutexes (or other suitable locking or lockless
> > > mechanism).
> > > When the non-main threads need to add fd events to the main loop, add
> > > the fd to the main list then write() 1 byte to the sentinel pipe.
> > > The write() will cause the main loop to run a fd handler that will take
> > > care of drying up both the pipe and the main list and create appropriate
> > > fd events in it.
> > 
> > Sounds like a plan. Do you really need the "main list"?
> > Can't you just write the fd number into the pipe? While it's
> > in transit, its ownership might be a bit undefined, but you
> > might get away without mutexes.
> 
> Maybe if using sendmsg() to avoid having the pipe go out of sync in case
> of bugs and trashing any following communication.

Local sendmsg dup's fds that you have to close. Another
syscall that you might want to avoid.

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de


More information about the samba-technical mailing list