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

Re: [Libevent-users] Wait until the loop thread processes all the data?



Actually there might be a problem here. You say the first thread produces, the second thread calls dispatch to consume. 

But you want to shut down the program from the first thread.

Can you change your program so the thread doing the consumption terminated when it’s finished instead of the producer?

> On Feb 20, 2018, at 3:03 AM, Egor Tensin <egor@xxxxxxxx> wrote:
> 
> Hello,
> 
> Hopefully you can help me with a libevent issue that I'm stuck on. I
> have two threads, one of which produces data, and the other runs
> event_base_dispatch (receiving the data from the first thread,
> processing it and sending it somewhere else). They communicate using a
> pair of bufferevents (over a local socket pair). The issue is, the
> first thread might be done with producing the data, program
> termination being the next logical step. But I want to wait for the
> second thread to 1) receive _all_ the data the first thread sent, 2)
> process it and 3) send it to the final destination. I can't figure out
> how to accomplish that, because if I call event_base_loopexit after
> the first thread stops, it looks like the second thread exits right
> after executing the current round of callbacks, discarding the latest
> data that might have been sent by the first thread. Can somebody
> please explain to me how to fix this? I can set a random timeout for
> event_base_loopexit, but this is unreliable, isn't it?
> 
> Regards,
> Egor Tensin.
> ***********************************************************************
> 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.