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

Re: [Libevent-users] Infinity loop



Thanks for the reply. If I understand you correctly you use event_set while the event is still on the event-loop?

In my case I also call event_set but I do it _after_ the callback function was called and since I do not use EV_PERSIST it means that libevent did an event_del for me before it called the callback function. I.e. the event was removed from the loop queue.

So I do something like this after the callback was called, where a is just some ADT.

	event_set(a->e, a->fd, EV_READ, read_cb, a);
        event_base_set(R->eventbase, a->e);
        event_priority_set(a->e,  a->priority);
	event_add(a->e, a->timeout);

The reason I use event_set is to be able to reset the event as I preallocate all event structs in a table keyed on fds and I *reuse* the events. AFAIK the above should be legal, but still, I experiences infrequent an infinity loop in event.c:timeout_process in the while- loop popping events from the timeheap where it pops an event and reinsert the same event so this while loop never exists:

	while ((ev = min_heap_top(&base->timeheap))) {
		if (evutil_timercmp(&ev->ev_timeout, &now, >))
			break;

		/* delete this event from the I/O queues */
		event_del(ev);

		event_debug(("timeout_process: call %p",
			 ev->ev_callback));
		event_active(ev, EV_TIMEOUT, 1);
	}



On 5. okt. 2009, at 09.44, nicolas dumont wrote:

Hello

I've had the same behaviour, exactly in same function event_active()

It was due to the fact that I ran event_set() after doing event_add () of the same event.
In that case, the internal flags are resetted by the event_set().
Then the event state is lost and can't be deleted,
and because there's not trap for that in libevent code, you fall in infinite loop.
*

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