[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] weird paired buffer event
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] weird paired buffer event
- From: 邵鄭叡 <vampirictutor@xxxxxxxxx>
- Date: Fri, 19 Jun 2020 13:10:59 +0800
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Fri, 19 Jun 2020 01:11:03 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=LxC54XF/rrTa9spiSvZMgDdKLw27gzdCyCC3KAHn+ZA=; b=hwZfeZzNaUvTct7fQZP3GcF0sFyAVZvK20EJc46N/BYr7x6Cf39d3NIU2eoItc1zE+ EE5kX+rlUghPdtcMpeak3GaqnPPTkzJyGirdIU/nLuj/QlvRJ4WTcWWYc9qUPsVxGiP2 qll3hl5aSPdYfa7r/iq2fyYhp+T5yvXEiNIj6RaB2/JlU87zUVKM8lTsbmO9r5kv5dQc /i4+i0cCckcufTs90fnUe5OcgQobttAwHhQL+8u/IvimgpIL640iBcGR2YyEUXxp6QgV 9M2ZBAsAdWDsvaX0P9+9OBki3McxYNfNaCOiBjoqQy+PpNfoJ/aD6sUujkta7nk04N81 tWMQ==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hi, I am developing a server app with libevent now.
My app has a main thread with event loop handling all network
comm/timer events,
and a worker thread to do some 'labor' stuff like DB operation.
I use a pair of buffered event to inter-comm between main thread and
worker thread.
like this in main thread:
bufferevent_pair_new( get_event_base() , BEV_OPT_THREADSAFE , pair);
bufferevent_setcb(pair[0], trampoline_readable,trampoline_writable
, trampoline_event , (void*) this);
bufferevent_enable(pair[0], EV_WRITE | EV_READ );
same does pair[1];
Now I write some message in worker thread like this:
bufferevent_write(bev, data, size);
I expect that read_cb could be awaken immediately in main thread, but
it doesn't.
The read_cb deferred infinitely until other event occurs (i.e. timer
or siginal),
the I can successfully fetch msg from read_cb.
Am I missing something?
I create the buffered event pair in main thread while write to one of
them in worker thread, is this OK?
Thanks in advance.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.