tevent in multithreaded programs

Simo simo at samba.org
Sat Jan 31 08:27:59 MST 2015


On Sat, 2015-01-31 at 14:03 +0100, Volker Lendecke wrote:
> 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.

First time I hear of this, do you have a pointer where I can read
further about this behavior ?

Simo.



More information about the samba-technical mailing list