libev out of context thread
Varun Chandramohan
cvaruneng04 at gmail.com
Thu Dec 12 00:12:57 CET 2013
Hi Marc,
Thanks for the reply. Not sure why the code formatting is weird. I started
using async watchers and it helped. I got it working with that. I did
remove one other thread as I felt it was not needed with async watcher.
My solution is to use thread 1 to read from socket a packet add it to queue
and immediately notify the async watcher of data available. I also added
mutex lock to avoid race condition. Everything seem to be working well
as expected. I have currently put the code under stress test. Thanks for
the help.
Regards,
Varun
On Wed, Dec 11, 2013 at 7:31 PM, Marc Lehmann <schmorp at schmorp.de> wrote:
> On Wed, Dec 11, 2013 at 01:11:02PM +1100, Varun Chandramohan <
> cvaruneng04 at gmail.com> wrote:
> > Once I have a sd to add to loop can I call
> >
> > ev_io_init(&d_packet->io, connect_ps_cb, d_packet->connect_sd,
> EV_WRITE|
> > EV_READ);
>
> Funny code formatting in your e-mail.
>
> Anyways, if I understand your mail correctly, you want to add watchers to a
> loop running in another thread.
>
> That's fine, as long as you lock the loop (just like your array) with a
> mutex or so. See the thread locking example in the manpage. You can use an
> async watcher to wake up the loop after you changed it.
>
> Whether overall ti is a good approach I can't tell from your mail, but
> adding threads rarely make things better, they do make things much more
> complex and error prone usually.
>
> --
> The choice of a Deliantra, the free code+content
> MORPG
> -----==- _GNU_ http://www.deliantra.net
> ----==-- _ generation
> ---==---(_)__ __ ____ __ Marc Lehmann
> --==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
> -=====/_/_//_/\_,_/ /_/\_\
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20131212/4dd45d49/attachment.html>
More information about the libev
mailing list