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

Re: [Libevent-users] std::threads



Thanks, Azat. You are really helpful!

On 03/20/2016 11:17 AM, Azat Khuzhin wrote:
On Sun, Mar 20, 2016 at 11:10:47AM -0400, Michael wrote:
Ugh, you don't need this wrapper, since evbuffer_get_length() will use
bufferevent's lock automatically.
bufferevent_lock(bev_) and bufferevent_unlock(bev_) should not be used????

How about bufferevent_write()???
evbuffer/bufferevent's are thread-safe, so the answer is *no*.

If we take a look at bufferevent_write() code we will see:
   evbuffer_add()

Which is:
   int
   evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
   {
       ...
       EVBUFFER_LOCK(buf);

And this is:
#define EVBUFFER_LOCK(buffer) EVLOCK_LOCK((buffer)->lock, 0)
#define EVLOCK_LOCK(lockvar,mode) if (lockvar) evthreadimpl_lock_lock_(mode, lockvar);

So IOW if buf->lock != NULL then it is thread-safe, and as I already mentioned
it will be not null if you pass BEV_OPT_THREADSAFE to bufferevent (and also you
need to enable one of locking mechanisms pthread/win32/your-own), since in this
case bufferevent->{output,input} will have the save lock as bufferevent.

I hope this will help.

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

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