Question

libevent claims to be thread-safe, but I'm wondering if that means we don't need to run bufferevent_write protected by mutexes.

I'd like to run the function bufferevent_write of libevent in several different threads and they can be executed at the same time.

According to the documentation, bufferevent_write function adds data to a bufferevent’s output buffer, so it needs to protect the buffer, but I don't know whether it is already protected by a mutex or if I have to protect it manually?

Was it helpful?

Solution

By looking at the source code of libevent it seems the mutexes are not included.
bufferevent_write calls evbuffer_add. I found the source code of this function here: http://transmission.sourcearchive.com/documentation/1.75/event_8h_b652a2f82d23509713258a6e44697164.html#b652a2f82d23509713258a6e44697164
So I think I have to call these two functions:

void evbuffer_lock(struct evbuffer *buf);
void evbuffer_unlock(struct evbuffer *buf);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top