[Cppcms-users] multithread safety in async application
Brought to you by:
artyom-beilis
|
From: Markus R. <us...@ma...> - 2013-04-01 13:14:41
|
Hi Artyom!
> Once you called async_flush_output you must wait for completion
> handler to be executed before you send more data.
Do you mean by "send more data" streaming to response().out() or do you mean
calling async_flush_output again?
Is following sequence correct or did I misunderstood something?
publish thread 1 |publish thread 2 |async cppcms thread
mutex.lock() | |
response().out()<< | |
response().out()<< | |
async_flush_output()| |
| |
| |in on_complete()
| |mutex.unlock()
|mutex.lock() |
|response().out()<< |
|response().out()<< |
|async_flush_output()|
| |
| |in on_peer_reset()
| |mutex.unlock()
stop sending |stop sending |
Is there a better sequence (that the threads can work more in parallel)?
So I need to have a mutex between:
- before calling response().out()
and:
- on_complete() or on_peer_reset().
Do I have a guarantee that either on_peer_reset() (callback of
cppcms::http::context::async_flush_output) or on_complete() (callback of
cppcms::http::context::async_on_peer_reset) is called in any case?
> For example "state" sse service does exactly the same it sends
> only latest data and if some was missed between async_flush_output
> and completion handler it would not be sent, but rather latest
> data should be.
Thank you for the examples, they are really great!
> About buffering,
>
> when you work with async app. the write to response().out()
> just collects the data to the buffer, the I/O is performed
> uput async_flush_output request and than you can continue
> once you receive the notification.
Ok, good to know. See questions aboved about when exactly I am allowed to
continue.
> So in general what you described is reasonable approach.
Thanks,
Markus Raab
|