using
in C++Date: | July 10, 2017 / year-entry #157 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20170710-00/?p=96565 |
Comments: | 4 |
Summary: | A trip around the block. |
Some follow-up notes on
Emulating the C# The main complication that prevented us from using RAII was the use of the Parallel Patterns Library (PPL) to express asynchronous programming in C++.¹ The most general pattern for asynchronous programming is that you start an operation, and then specify a callback to be invoked when the operation completes. In traditional C-style programming, this callback is a boring function pointer, coupled with some reference data so the callback has context for why it is being called back. C++ provides lambdas which let you express the continuation as a callback object, which is much more convenient since you can express the control flow inline instead of having tiny pieces of control flow scattered all over your program. And lambda capture makes it easy to express what pieces of information needs to be carried forward to the continuation.
If we didn't have any asynchronous operations, then a basic RAII
class would do the trick:
When the RAII class destructs, the cleanup operation occurs.
(In our example, the cleanup operation is calling
The magical step was the
introduction of the not-yet-standard-but-hopefully-soon
As a result, switching to
¹
There's also
|
Comments (4)
Comments are closed. |
Having recently used
co_await
with cppwinrt for some sockets code it is indeed wonderful magical pixie dust that I can’t wait to get fully standardized.The concurrency TS has future::then, which makes it composable.
This is probably the blog platform’s fault and out of your control, but the social links on this article have some busted HTML with unescaped quotes in their attributes:
<a data-social='{"type":"twitter", "url":"https://blogs.msdn.microsoft.com/oldnewthing/20170710-00/?p=96565", "text": "On the circular path from RAII to crazy-town back to RAII: Thoughts on emulating C#'s
using
in C++”}’ href=”#” id=”post_tweet_count”>0Workaround: remove the apostrophe from the article title, since other articles aren’t quite as busted as this one.
Yeah, I’ve opened a ticket with the blog platform team.
Meanwhile, I changed the ‘ to ' to work around the problem.They asked me to turn the corruption back on so they can investigate.