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

Re: [Libevent-users] using event_base_loop withy timer events



Thanks Azat,

It's definitely fixed the problem. Yes, we are calling "evthread_use_pthreads" in prod.Â

On Tue, Oct 27, 2015 at 9:28 AM, Azat Khuzhin <a3at.mail@xxxxxxxxx> wrote:
On Sat, Oct 24, 2015 at 01:43:37PM +0300, Roman Gershman wrote:
> The short example is provided here :
> https://gist.github.com/romange/6d1d5c51e7dd8054fbf8
> The version I am using is version 2.0.21-stable
>
> When line 16 is commented out (#define EVENT_FLAG 0) the bug is reproduced.
>
>
> for the 'good' version you should get output:
>
> version 2.0.21-stable
> 18
>
> and in the problematic version the counter is 1.
>
>
> On Thu, Oct 22, 2015 at 7:34 PM, Azat Khuzhin <a3at.mail@xxxxxxxxx> wrote:
>
> > On Thu, Oct 22, 2015 at 07:02:53PM +0300, Roman Gershman wrote:
> > > Hi,
> > > my ebase thread does the following loop
> > >
> > > while ((res = event_base_loop(ebase_, EVLOOP_ONCE)) == 1) {
> > > }
> > >
> > >
> > > and the other (main) adds timer event that runs every millisecond. It
> > adds
> > > the event *after* the ebase thread calls event_base_loop.
> > >
> > > event* ev = event_new(base(), -1, EV_PERSIST | EV_TIMEOUT, &PeriodicCb,
> > > data);
> > > CHECK_EQ(0, event_add(ev, &tv));
> > >
> > >
> > > I see that this event does not run. If I change flags from EVLOOP_ONCE
> > to 0
> > > it does run well.
> > > How should I make event base to realize that the new event is added?

Hi Roman,

Right now you have:
 while (event_base_loop(base, EVLOOP_ONCE)) {
 }

But this will work only when you don't have any events, since when you
will have event event_base_loop() will return *zero* not *one*, and once
persistent event added you will have events and it will return *zero*,
IOW if you simply change you loop like this:
 while (event_base_loop(base, EVLOOP_ONCE) >= 0) {
 }

It must works like you want (if I understand correctly).

Also consider to enable pthread to avoid races (this is not the case for
this sample, but I don't know what you have in real):
 evthread_use_pthreads()

Cheers,
Azat.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users  in the body.



--
Roman GershmanÂ|ÂArchitectÂ|ÂUbimo
+972-542-451046Â|Âroman@xxxxxxxxxÂ|ÂLinkedInÂ|Â@ubimoincÂ|Âwww.ubimo.com