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

[Libevent-users] bufferevent_pair_new vs socketpair



Title: bufferevent_pair_new vs socketpair
Hello libevent gurus!

I'm trying to implement multithreaded libevent application and have a few questions.

Consider there are two threads: thread_1 and thread_2, each running using its own separate event base, so libevent is not configured to be thread safe.

Now I need these two threads to communicate to each other, but I don't like to introduce any locks, so I'm wondering what mechanism is better to use: bufferevent_pair_new or socketpair? 

Do I have to use BEV_OPT_THREADSAFE with bufferevent_pair_new if the first thread will always write the data into the one end of bufferevent_pair and the second thread will always read the data from another end of the bufferevent_pair?

With socketpair(AF_UNIX), I don't need to use locks, but it requires syscalls.

Looking through the sources of libevhtp (
https://github.com/ellzey/libevhtp/blob/master/evthr/evthr.c#L283) I found that for multithreading this library uses socketpairs and I don't understand why so if there is bufferevent_pair. 

So, what is the preferable and faster way to communicate between threads?

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