Fix deadlock in case of evconnlistener_disable() in parallel with callback I've got an issue when stop evconnlistener not in the event_base_loop() thread. evconnlistener_disable() acquired lev->lock, if the same time, user callbacks is runing, the event thread released lock, after callback finished, it try to aquire the lock again, I think this makes conflict: Here is backtraces: thread 1: 0 __lll_lock_wait (futex=futex@entry=0x555555559a60, private=0) at lowlevellock.c:52 1 0x00007ffff7f2a131 in __GI___pthread_mutex_lock (mutex=0x555555559a60) at ../nptl/pthread_mutex_lock.c:115 2 0x00007ffff7f424c9 in evthread_posix_lock (mode=0, lock_=0x555555559a60) at evthread_pthread.c:79 3 0x00007ffff7f7dc12 in listener_read_cb (fd=7, what=2, p=0x5555555599a0) at listener.c:439 4 0x00007ffff7f6d758 in event_persist_closure (base=0x555555559370, ev=0x5555555599d8) at event.c:1645 5 0x00007ffff7f6da60 in event_process_active_single_queue (base=0x555555559370, activeq=0x5555555597e0, max_to_process=2147483647, endtime=0x0) at event.c:1704 6 0x00007ffff7f6e018 in event_process_active (base=0x555555559370) at event.c:1805 7 0x00007ffff7f6e92a in event_base_loop (base=0x555555559370, flags=0) at event.c:2047 8 0x0000555555555449 in main () at test_listen.c:67 thread 2: 0 futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0x555555559858) at ../sysdeps/nptl/futex-internal.h:183 1 __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x555555559800, cond=0x555555559830) at pthread_cond_wait.c:508 2 __pthread_cond_wait (cond=0x555555559830, mutex=0x555555559800) at pthread_cond_wait.c:638 3 0x00007ffff7f426f3 in evthread_posix_cond_wait (cond_=0x555555559830, lock_=0x555555559800, tv=0x0) at evthread_pthread.c:162 4 0x00007ffff7f70bc5 in event_del_nolock_ (ev=0x5555555599d8, blocking=2) at event.c:2934 5 0x00007ffff7f70748 in event_del_ (ev=0x5555555599d8, blocking=2) at event.c:2821 6 0x00007ffff7f707a1 in event_del (ev=0x5555555599d8) at event.c:2830 7 0x00007ffff7f7d76e in event_listener_disable (lev=0x5555555599a0) at listener.c:343 8 0x00007ffff7f7d6e5 in evconnlistener_disable (lev=0x5555555599a0) at listener.c:325 9 0x00005555555552c3 in disable_thread (arg=0x5555555599a0) at test_listen.c:27 10 0x00007ffff7f27609 in start_thread (arg=<optimized out>) at pthread_create.c:477 11 0x00007ffff7e4e293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95