Topic: Questions about N3558 (A Standardized Representation
Author: Fernando Pelliccioni <fpelliccioni@gmail.com>
Date: Fri, 22 Mar 2013 15:05:56 -0300
Raw View
--14dae9340af98eefd704d8874ee5
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I wonder if the following pseudo-code should run the continuation in the
UI Thread ( or not ).
// Begin code -----------------------------------------------
// executed on UI Thread
void UiWindow::widgetEventHandler()
{
startGIFAnimation(); //modifies the UI
// (1) async task, executed on another thread
auto f1 = boost::async( boost::launch::async, []() {
return doSomeHeavyWork();
});
// (2) continuation, must be executed on UI thread ( or crash )
auto f2 = f1.then( boost::launch::deferred, [this](
boost::future<string> & f ) {
string result = f.get();
stopGIFAnimation(); //modifies the UI
writeOnWindowLabel(result); //modifies the UI
});
f2.wait(); // (3) blocks the UI
}
// End code -----------------------------------------------
Note that I launch the continuation using a launch::deferred policy.
But I don't know exactly what this means in the context of the then()
function.
std::async( std::launch::deferred, F.... ) means that F will be executed in
the current thread.
But, what about future::then ? Should it behave the same way?
Or should I use an executor to achieve the desired effect?
If the executor is required to change the execution context of the
continuation. What is the purpose of the launch policy ( on then() function
) ?
Note: Ignore the blocking of the UI Thread on (3), I have doubts about
this, but I will write them in another post.
Thanks and regards,
Fernando Pelliccioni.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
--14dae9340af98eefd704d8874ee5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>=A0Hi,</div><div><br></div><div>=A0I wonder if the fo=
llowing pseudo-code should run the continuation in the UI Thread ( or not )=
..</div><div><br></div><div>// Begin code ----------------------------------=
-------------</div>
<div>// executed on UI Thread</div><div>void UiWindow::widgetEventHandler()=
</div><div>{</div><div>=A0 =A0 startGIFAnimation();<span class=3D"" style=
=3D"white-space:pre"> </span>//modifies the UI</div><div>=A0 =A0=A0</div><d=
iv>=A0 =A0 // (1) async task, executed on another thread</div>
<div>=A0 =A0 auto f1 =3D boost::async( boost::launch::async, []() {</div><d=
iv>=A0 =A0 =A0 =A0 return doSomeHeavyWork();</div><div>=A0 =A0 });</div><di=
v><br></div><div>=A0 =A0 // (2) continuation, must be executed on UI thread=
( or crash )</div>
<div>=A0 =A0 auto f2 =3D f1.then( boost::launch::deferred, [this]( boost::f=
uture<string> & f ) {</div><div>=A0 =A0 =A0 =A0 string result =3D=
f.get();</div><div>=A0 =A0 =A0 =A0 stopGIFAnimation(); =A0 =A0 =A0 =A0 //m=
odifies the UI</div><div>=A0 =A0 =A0 =A0 writeOnWindowLabel(result); //modi=
fies the UI</div>
<div>=A0 =A0 });</div><div><br></div><div>=A0 =A0 f2.wait(); // (3) blocks =
the UI</div><div>}</div><div>// End code ----------------------------------=
-------------</div><div><br></div><div><br></div><div>Note that I launch th=
e continuation using a launch::deferred policy.</div>
<div>But I don't know exactly what this means in the context of the the=
n() function.</div><div><br></div><div>std::async( std::launch::deferred, F=
..... ) means that F will be executed in the current thread.</div><div>But, =
what about future::then ? Should it behave the same way?=A0</div>
<div>Or should I use an executor to achieve the desired effect?</div><div><=
br></div><div>If the executor is required to change the execution context o=
f the continuation. What is the purpose of the launch policy ( on then() fu=
nction ) ?</div>
<div><br></div><div>Note: Ignore the blocking of the UI Thread on (3), I ha=
ve doubts about this, but I will write them in another post.</div><div><br>=
</div><div><br></div><div>Thanks and regards,</div><div>Fernando Pelliccion=
i.</div>
</div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
--14dae9340af98eefd704d8874ee5--
.