tevent in multithreaded programs
simo at samba.org
Fri Jan 30 15:37:39 MST 2015
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.
More information about the samba-technical