没有合适的资源?快使用搜索试试~ 我知道了~
首页c++ 2017 协程
资源详情
资源评论
资源推荐

Coroutines in
C++17
MOST EFFICIENT, MOST SCALABLE, MOST
OPEN COROUTINES OF ANY PROGRAMMING
LANGUAGE IN EXISTENCE!
CppNow 2015 • Gor Nishanov (gorn@microsoft.com) • Microsoft

What this talk is about?
• Stackless Resumable Functions
• Lightweight, customizable coroutines
• C++17 (maybe)
• Experimental Implementation in
MSVC 2015, Clang in progress, EDG
2012 - N3328
2013 - N3564
2013 - N3650
2013 - N3722
2014 - N3858
2014 - N3977
2014 - N4134 EWG direction
approved
2014 - N4286
2015 - N4403 EWG accepted,
sent to Core WG
Deon Brewis
Niklas Gustafsson
Herb Sutter
Jim Radigan
Daveed Vandevoorde
CppNow 2015 • Coroutines in C++17 2
http://isocpp.org/files/papers/N4403.pdf
http://isocpp.org/files/papers/N4402.pdf

Coroutines are popular!
Python: PEP 0492 (accepted on May 5, 2015)
async def abinary(n):
if n <= 0:
return 1
l = await abinary(n - 1)
r = await abinary(n - 1)
return l + 1 + r
HACK (programming language)
async function gen1(): Awaitable<int> {
$x = await Batcher::fetch(1);
$y = await Batcher::fetch(2);
return $x + $y;
}
DART 1.9
Future<int> getPage(t) async {
var c = new http.Client();
try {
var r = await c.get('http://url/search?q=$t');
print(r);
return r.length();
} finally {
await c.close();
}
}
C#
async Task<string> WaitAsynchronouslyAsync()
{
await Task.Delay(10000);
return "Finished";
}
C++17
future<string> WaitAsynchronouslyAsync()
{
await sleep_for(10ms);
return "Finished“s;
}
CppNow 2015 • Coroutines in C++17 3

Design Goals
• Scalable (to hundred millions of concurrent coroutines)
• Efficient (resume and suspend operations comparable in cost
to a function call overhead)
• Seamless interaction with existing facilities with no
overhead
• Open ended coroutine machinery allowing library designers
to develop coroutine libraries exposing various high-level
semantics, such as generators, goroutines, tasks and more.
• Usable in environments where exception are forbidden or not
available
4CppNow 2015 • Coroutines in C++17

2 x 2 x 2
• Two new keywords
• await
• yield
• Two new concepts
• Awaitable
• Coroutine Promise
• Two new types
• coroutine_handle
• coroutine_traits
CppNow 2015 • Coroutines in C++17 5
(*) may change based on discussion at the Lenexa last week
(*)
剩余61页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0