[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] event_add from a different thread while event loop is running
- To: libevent-users@xxxxxxxx
- Subject: [Libevent-users] event_add from a different thread while event loop is running
- From: "D.P." <pizdes@xxxxxxxxx>
- Date: Mon, 2 May 2011 19:18:57 -0400
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Mon, 02 May 2011 19:19:05 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=4CxnFaTCBLMSrU0ysAqijIF7PP/aQ2nixgD2CN4IZs8=; b=cNYxFM2WSBPu3/PkOxwCJYSokrpXTWpiq3lfLGuguWekLlURf1Ps6q2yDoK6JDMhlo 5Cf2Op/JVR33y4FfDhNoS+CqYtD97vHHyFG72Wzd9MFah53Fcnecby/8phfITMBdycTf nVaf9L2C6p3P25wMHsP5GOE4tM09jKbRasfHY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=gDKPo3VNTXAfhVYJkmUhc0NZs+DWvz+4XUb3V3+eQLImPD7mimykq21BduiruCTTTs 5DZf8RHjrzfiHW+C4QeYWrzd0/rbb/2Q1g+O0+9lDzpK5uboOK1IXfnjaWmuygUGijul V6PEGCy4URLuhtPnh/mupKqSKgT99qo6n0wGs=
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hi, I have a question regarding adding an event from a different thread (different from the one event_base_dispatch was called).
Initially I create an event_base, add a listener socket to it, and do event_base_dispatch. When a listener socket gets an incoming connection, it
will add the new client socket (from inside the callback) to event_base. Everything works as expected up to this point (i.e. client socket callback is invoked whenever there is data
to read, and listener socket is invoked whenever there is another client trying to connect.) Now I add another socket using event_add, but from a different
thread. Now let's say some data arrives at this socket that I have just added. It seems that a callback for this socket will only get invoked *after* there
is some activity on the other two sockets (listener or client from before). So if there is no activity at all on the two sockets that were added before, the callback
for this new socket will never get called. I tested the same code on OS X with kqueue and poll backends, and on Linux with epoll and poll. This does not happen
with epoll (the new socket callback will be fired even if there is no activity on the other two), but does happen with kqueue and poll. Is there anything I can do
to "force" an immediate refresh (while the event loop is running) of the set of watched sockets for systems that use kqueue or poll?
Thanks