On Tue, Jan 3, 2012 at 6:45 PM, Ralph Castain <r...@open-mpi.org> wrote: > Hi folks > > I'm trying to use libevent 2.0.13 with priorities, and am having a problem > when signal events are defined. Basically, this is what I do: > > 1. create an event base > > 2. call event_base_priority_init(base, 8) > > 3. event_assign(&event, base, SIGTERM, EV_SIGNAL|EV_PERSIST, cbfunc, &event) > > 4. event_priority_set(&event, 1) > > 5. event_add(&event, NULL) > > This is accepted just fine. However, when I subsequently call > event_base_free(base), libevent crashes: > > 729 struct event *next = TAILQ_NEXT(ev, ev_next); > (gdb) where > #0 0x0000000100157be2 in event_base_free (base=0x1003046f0) at event.c:729 > > > Any ideas on what might be happening?
Not really. I just tried to do what you said you were doing above, and I can't reproduce the same problem with 2.0.16-stable. I tried it again with Libevent 2.0.13-stable, and got the same result: worked fine. I'm attaching my test code so you can see if you get different results. > My program works fine (all other events cause no problem) so long as I remove > these signal events. Do signal events not work with priority queues, at least > in 2.0.13? (First, a terminology aside: "priority queue" isn't what implements priorities in libevent. A priority queue is just a kind of abstract data structure that we use to implement timeouts for events.) But yeah, signals are supposed to work with event priorities, and in my (attached) test, it seems they do. Something else might be going on here. To try to debug this more, here are some ideas: * Try to see if your code works when you turn on Libevent's debugging mode. * See if valgrind (or a similar tool) finds any memory corruption issues * Try to tweak my (attached) test so that it reproduces the crash you're seeing. hoping this helps, -- Nick
#include <event2/event.h> #include <event2/event_struct.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> static void cbfunc(evutil_socket_t fd, short what, void *arg) { event_base_loopbreak(arg); } static void die(const char *msg) { fprintf(stderr, "%s\n", msg); exit(1); } int main(int argc, char **argv) { struct event_base *base; struct event ev; printf("Libevent %s\n", event_get_version()); if (!(base = event_base_new())) die("event_base_new"); if (event_base_priority_init(base, 8) < 0) die("event_base_priority_init"); if (event_assign(&ev, base, SIGTERM, EV_SIGNAL|EV_PERSIST, cbfunc, base)<0) die("event_assign"); if (event_priority_set(&ev, 1) < 0) die("event_priority_set"); if (event_add(&ev, NULL) < 0) die("event_add"); event_base_loop(base, 0); event_base_free(base); return 0; }