Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libevent Multithread Support

i have a few questions regarding libevent2 and its multithread support.

Does libevent support multiple Threads? What i would like to achieve is something like this:

  1. Create an event_base in a single thread.
    • In this single Thread setup events and associate them to the event base. Also register Callbacks for each observed event.
  2. As soon as an observed event occurs, execute the registered callback in some other (worker)thread.

Is it possible to do s.th like this with libevent? Or are there any other approaches to support multiple cores?

Thank you very much

like image 309
user109343 Avatar asked Dec 02 '22 23:12

user109343


1 Answers

If you add evthread_use_pthreads(); you must have -levent_pthreads

Example:

gcc chat.c -o chat -levent -lpthread -levent_pthreads

and:

$> ls /usr/lib/libevent*.a
/usr/lib/libevent.a  /usr/lib/libevent_core.a  /usr/lib/libevent_extra.a  /usr/lib/libevent_openssl.a  /usr/lib/libevent_pthreads.a
like image 198
kainan Avatar answered Feb 19 '23 13:02

kainan