[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Best way for additional events registration in the same thread



My original design was misguided. Of course calling Âevent_base_dispatch() means giving the running thread to libevent's event_base. I am still learning how it works...
On Thu, Nov 27, 2014 at 10:32 AM, Azat Khuzhin <a3at.mail@xxxxxxxxx> wrote:


On 27 Nov 2014 04:29, "Fongang Dassi Jean" <djfongang@xxxxxxxxx> wrote:
>
> Hello,
>
> atÂhttp://www.wangafu.net/~nickm/libevent-book/Ref3_eventloop.html, there is a note that
>
> "Ordinarily, the loop will exit as soon as it has no pending or active events. You can override this behavior by passing the EVLOOP_NO_EXIT_ON_EMPTY flag---for example, if youâre going to be adding events from some other thread."
>
> This seems to imply that it is only recommended to add events if another thread is used?

No, you could add events from callbacks too.

Thanks for pointing this out, it helped me understand how it all works. In the program bellow, the callbacks on the event attached to the pipe(g->fifo_event)Âare used to insert additional requests into to event_base.

>
> This program:Âhttps://raw.githubusercontent.com/bagder/curl/master/docs/examples/hiperfifo.cÂmanages to register additional events after dispatch is called, but seems to rely on the existence of a persisting event.

It has one timer.

I meant the fifo_event on the pipe seems to prevent the event_base from completing and exiting.Â

>
> Is that the only way? What is the best way?
>
> Thanks in advance