On Mon, Oct 23, 2006 at 11:04:49AM -0700, Edward Chan wrote:
> HI there,
> 
> I just started taking a look at libevent and had a couple questions.
> 
> 1. are the event_* api's thread safe?

So far as you can guarantee there is no contention for the struct event and
struct event_base objects.

> 2. how do you use EV_PERSIST flag?  I'm used to using poll where I add
> interest for read or write, then when the socket is readable/writable, I
> remove my interest for that event until my read/write would block again,
> then I add back my interest for this event again.

You can continue doing it this way, without using the EV_PERSIST flag.
But there are two other methods:

1) If that particular event is the core driver of all other events, you
simply set EV_PERSIST and let it drive everything else. E.g. the way
evbuffers are implemented.

2) You invert your typical poll methodology. Use EV_PERSIST and then use
event_del() when you do NOT want any more notifications. In many scenarios,
when a descriptor isn't blocking you continue reading/writing until it
_does_ block, w/ the expectation that your application can run faster than
the socket buffers can be re-filled. This is a sort of a middle ground
between the method you originally described and the higher-order #1 method.

Note that with poll and select you don't lose much by shifting an event in
and out of a polling state. However, with things like epoll() and kqueue()
you potentially incur a system call everytime you do switch the notification
state of each descriptor, which is costly.
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to