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

Re: [Libevent-users] questions about bufferevent callbacks in multithreaded code






On Fri, May 17, 2013 at 12:09 AM, Sashan Govender <sashang@xxxxxxxxx> wrote:



On Wed, May 15, 2013 at 3:37 PM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
On Wed, May 15, 2013 at 6:24 AM, Sashan Govender <sashang@xxxxxxxxx> wrote:
> So in theory the following scenarios should not deadlock:
>
> This all happens in a single thread:
> 1) a bufferevent read callback is triggered (lock acquired)
> 2) the user supplied callback function reads the data and calls
> bufferevent_write (lock acquired - ok because using a recursive mutex)

Right.

> and neither should this where 2 threads are involved:
> 1) a bufferevent read callback is triggered
> 2) the user supplied callback function does some stuff (callback ends ->
> lock released by libevent)
> 3) bufferevent_write is called from another thread

Right, so long as there isn't some kind of a deadlock scenario where
the two threads are acquiring locks in different order.

If you *are* hitting a mysterious bufferevent-related deadlock, though
,you might want to check out Libevent 2.1.3-alpha: it has a fix for a
longstanding tricky deadlock in bufferevents related to how
event_del() handles an event that is currently running its callback.

Thanks. I'll give 2.1.3-alpha a go. I'll also try and strip away more of my code till I have a reproducible case for libevent or I find the problem in my code. I've tried enabling the multithreaded debugging (evthread_enable_lock_debugging) but that doesn't trigger any assertions.

I've tried with the the 2.1.3-alpha of libevent and not noticed deadlocks, which is good. However while alternating between libevent 2.0 and the 2.1 alpha I noticed this error message come up when using the 2.0 stable:

[err] event_queue_remove: 0x8ca3a8(fd 8) not on queue 8

What does this imply? Does it mean that a thread deleted the fd and another thread came along and tried to perform the same removal of the fd and found that the fd did not exist because it was already removed?