SlideShare a Scribd company logo
C++20 Coroutine
Coroutine
코루틴은 자신의 상태를 유지하면서 실행을 일시 정지하거나 재개할 수 있는 함수
Coroutine
같은 스레드에서 제어권이 변경 되는 것이기 때문에 동기화 문제가 발생하지
않는다
쓰레드 보다 적은 비용이 든다
코루틴 객체는 힙에 생성이 된다
코루틴 객체의 수명에 유의 해야 한다
구현이 어렵다(C++, 개인적인 생각…)
코루틴을 적용할 수 없는 함수들
가변 인자
일반 return 문을 사용
constexpr, consteval
생성자, 소멸자
main
추가된 키워드
co_await 표현식 : 재개 될 때까지 일시 중지
std::size_t n = co_await socket.async_read_some(buffer(data));
co_yield 표현식 : 값을 반환하고 일시 중지
while (true) co_yield n++;
co_return 문 : 값을 반환하고 끝낸다
co_return 7;
구현시 필요한 것들
promise
"코루틴 내부"에서 관리 되는 객체. 코루틴의 결과나 예외를 이 객체를 통해
호출자에게 전달 하는 용도로 사용
코루틴 핸들
"코루틴 외부"에서 관리 되는 객체. 코루틴을 resume하거나 코루틴 프레임을
제거 할 때 사용
코루틴 프레임
"힙 메모리 영역"에 할당 되는 코루틴 상태를 나타내는 객체
promise
아래의 멤버 함수 중 일부를 구현해야한다
구현한 함수는 컴파일러가 자동으로 호출한다
코루틴 핸들
promise_type이라는 내부 형식을 정의하고 있어야한다
직접 정의하거나 std::coroutine_traits를 Generator로 특수화한
std::coroutine_traits<Generator>를 public 형식 멤버 promise_type으로 두어도
된다.
코루틴 프레임
약속 객체, 코루인 인수들의 복사본, 정지 시점을 나타내는 객체, 내부의 지역 변수
등으로 구성됨
대기 가능 객체
코루틴이 일시정지 중인지 아닌지 판정
대기자 객체
대기 가능 객체가 종료 혹은 일시 정지 되길 기다리는 객체
co_await 연산자를 정의하거나 대기 가능 객체를 대기자 객체로 변환해야 한다
대기 가능 객체
Awaitable 콘셉트를 충족해야 함
정의 되어있는 std:: suspend_always 와 std::suspend_never 타입을 사용해도 된다
예제 코드
예제 코드
예제 코드 - 호출 순서
예제 코드 2
예제 코드 2
예제 코드 2

More Related Content

What's hot

NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
Jaeseung Ha
 
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012devCAT Studio, NEXON
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
Sang Heon Lee
 
리플렉션과 가비지 컬렉션
리플렉션과 가비지 컬렉션리플렉션과 가비지 컬렉션
리플렉션과 가비지 컬렉션
QooJuice
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
NAVER D2
 
심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018
심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018
심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018
devCAT Studio, NEXON
 
Python 게임서버 안녕하십니까 : RPC framework 편
Python 게임서버 안녕하십니까 : RPC framework 편Python 게임서버 안녕하십니까 : RPC framework 편
Python 게임서버 안녕하십니까 : RPC framework 편
준철 박
 
빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)
YEONG-CHEON YOU
 
행동 트리
행동 트리행동 트리
행동 트리
Sukwoo Lee
 
게임서버프로그래밍 #8 - 성능 평가
게임서버프로그래밍 #8 - 성능 평가게임서버프로그래밍 #8 - 성능 평가
게임서버프로그래밍 #8 - 성능 평가
Seungmo Koo
 
[NDC 2009] 행동 트리로 구현하는 인공지능
[NDC 2009] 행동 트리로 구현하는 인공지능[NDC 2009] 행동 트리로 구현하는 인공지능
[NDC 2009] 행동 트리로 구현하는 인공지능
Yongha Kim
 
PINTOS Operating system homework 2
PINTOS Operating system homework 2PINTOS Operating system homework 2
PINTOS Operating system homework 2
Gichan Lee
 
그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기
Yongha Kim
 
야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계
야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계
야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계
승명 양
 
실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략
YEONG-CHEON YOU
 
[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기
[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기
[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기
강 민우
 
전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013
전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013
전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013devCAT Studio, NEXON
 
[Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용
[Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용 [Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용
[Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용
MinGeun Park
 
머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018
머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018
머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018
Taehoon Kim
 
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이 왜 이리 힘드나요? (Lock-free에서 Transactional Memory까지)
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이  왜 이리 힘드나요?  (Lock-free에서 Transactional Memory까지)Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이  왜 이리 힘드나요?  (Lock-free에서 Transactional Memory까지)
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이 왜 이리 힘드나요? (Lock-free에서 Transactional Memory까지)
내훈 정
 

What's hot (20)

NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
 
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
 
리플렉션과 가비지 컬렉션
리플렉션과 가비지 컬렉션리플렉션과 가비지 컬렉션
리플렉션과 가비지 컬렉션
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
 
심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018
심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018
심예람, <프로젝트DH> AI 내비게이션 시스템, NDC2018
 
Python 게임서버 안녕하십니까 : RPC framework 편
Python 게임서버 안녕하십니까 : RPC framework 편Python 게임서버 안녕하십니까 : RPC framework 편
Python 게임서버 안녕하십니까 : RPC framework 편
 
빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)
 
행동 트리
행동 트리행동 트리
행동 트리
 
게임서버프로그래밍 #8 - 성능 평가
게임서버프로그래밍 #8 - 성능 평가게임서버프로그래밍 #8 - 성능 평가
게임서버프로그래밍 #8 - 성능 평가
 
[NDC 2009] 행동 트리로 구현하는 인공지능
[NDC 2009] 행동 트리로 구현하는 인공지능[NDC 2009] 행동 트리로 구현하는 인공지능
[NDC 2009] 행동 트리로 구현하는 인공지능
 
PINTOS Operating system homework 2
PINTOS Operating system homework 2PINTOS Operating system homework 2
PINTOS Operating system homework 2
 
그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기
 
야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계
야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계
야생의 땅: 듀랑고의 시뮬레이션 MMO 샌드박스 설계
 
실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략
 
[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기
[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기
[IGC 2017] 펄어비스 민경인 - Mmorpg를 위한 voxel 기반 네비게이션 라이브러리 개발기
 
전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013
전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013
전형규, M2 클라이언트 스레딩 아키텍쳐, NDC2013
 
[Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용
[Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용 [Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용
[Unite17] 유니티에서차세대프로그래밍을 UniRx 소개 및 활용
 
머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018
머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018
머신러닝 해외 취업 준비: 닳고 닳은 이력서와 고통스러웠던 면접을 돌아보며 SNU 2018
 
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이 왜 이리 힘드나요? (Lock-free에서 Transactional Memory까지)
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이  왜 이리 힘드나요?  (Lock-free에서 Transactional Memory까지)Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이  왜 이리 힘드나요?  (Lock-free에서 Transactional Memory까지)
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이 왜 이리 힘드나요? (Lock-free에서 Transactional Memory까지)
 

Similar to C++20 Coroutine

More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshin
Dong Chan Shin
 
Effective c++(chapter 5,6)
Effective c++(chapter 5,6)Effective c++(chapter 5,6)
Effective c++(chapter 5,6)문익 장
 
Api design for c++ pattern
Api design for c++ patternApi design for c++ pattern
Api design for c++ pattern
jinho park
 
Api design for c++ ch3 pattern
Api design for c++ ch3 patternApi design for c++ ch3 pattern
Api design for c++ ch3 patternjinho park
 
Effective c++ Chapter1,2
Effective c++ Chapter1,2Effective c++ Chapter1,2
Effective c++ Chapter1,2문익 장
 
More effective c++ chapter1,2
More effective c++ chapter1,2More effective c++ chapter1,2
More effective c++ chapter1,2문익 장
 
HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3suitzero
 
이펙티브 C++ 스터디
이펙티브 C++ 스터디이펙티브 C++ 스터디
이펙티브 C++ 스터디
quxn6
 
포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++
KWANGIL KIM
 
Secure coding-c-dcl-1
Secure coding-c-dcl-1Secure coding-c-dcl-1
Secure coding-c-dcl-1
Seungyong Lee
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심흥배 최
 
연산자 오버로딩
연산자 오버로딩연산자 오버로딩
연산자 오버로딩
수빈 박
 

Similar to C++20 Coroutine (12)

More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshin
 
Effective c++(chapter 5,6)
Effective c++(chapter 5,6)Effective c++(chapter 5,6)
Effective c++(chapter 5,6)
 
Api design for c++ pattern
Api design for c++ patternApi design for c++ pattern
Api design for c++ pattern
 
Api design for c++ ch3 pattern
Api design for c++ ch3 patternApi design for c++ ch3 pattern
Api design for c++ ch3 pattern
 
Effective c++ Chapter1,2
Effective c++ Chapter1,2Effective c++ Chapter1,2
Effective c++ Chapter1,2
 
More effective c++ chapter1,2
More effective c++ chapter1,2More effective c++ chapter1,2
More effective c++ chapter1,2
 
HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3
 
이펙티브 C++ 스터디
이펙티브 C++ 스터디이펙티브 C++ 스터디
이펙티브 C++ 스터디
 
포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++
 
Secure coding-c-dcl-1
Secure coding-c-dcl-1Secure coding-c-dcl-1
Secure coding-c-dcl-1
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
 
연산자 오버로딩
연산자 오버로딩연산자 오버로딩
연산자 오버로딩
 

More from 진화 손

[C++ 20] [P1035R7] Input range adaptors.
[C++ 20] [P1035R7] Input range adaptors.[C++ 20] [P1035R7] Input range adaptors.
[C++ 20] [P1035R7] Input range adaptors.
진화 손
 
[C++ 20] [P0645R10] Text formatting 내용 정리
[C++ 20] [P0645R10] Text formatting 내용 정리[C++ 20] [P0645R10] Text formatting 내용 정리
[C++ 20] [P0645R10] Text formatting 내용 정리
진화 손
 
C++20 constexpr default constructor of std::atomic and std::atomic_flag
C++20 constexpr default constructor of std::atomic and std::atomic_flagC++20 constexpr default constructor of std::atomic and std::atomic_flag
C++20 constexpr default constructor of std::atomic and std::atomic_flag
진화 손
 
[C++ 20][P0325R4] std::to_array() 내용 정리.
[C++ 20][P0325R4] std::to_array() 내용 정리.[C++ 20][P0325R4] std::to_array() 내용 정리.
[C++ 20][P0325R4] std::to_array() 내용 정리.
진화 손
 
C++ 20 Efficient access to std::basic_stringbuf’s buffer
C++ 20 Efficient access to std::basic_stringbuf’s bufferC++ 20 Efficient access to std::basic_stringbuf’s buffer
C++ 20 Efficient access to std::basic_stringbuf’s buffer
진화 손
 
C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf
진화 손
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf
진화 손
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates
진화 손
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
진화 손
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions
진화 손
 
C++20 Utility functions to implement uses-allocator construction
C++20 Utility functions to implement uses-allocator constructionC++20 Utility functions to implement uses-allocator construction
C++20 Utility functions to implement uses-allocator construction
진화 손
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types
진화 손
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements
진화 손
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
진화 손
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
진화 손
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
진화 손
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
진화 손
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains
진화 손
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
진화 손
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
진화 손
 

More from 진화 손 (20)

[C++ 20] [P1035R7] Input range adaptors.
[C++ 20] [P1035R7] Input range adaptors.[C++ 20] [P1035R7] Input range adaptors.
[C++ 20] [P1035R7] Input range adaptors.
 
[C++ 20] [P0645R10] Text formatting 내용 정리
[C++ 20] [P0645R10] Text formatting 내용 정리[C++ 20] [P0645R10] Text formatting 내용 정리
[C++ 20] [P0645R10] Text formatting 내용 정리
 
C++20 constexpr default constructor of std::atomic and std::atomic_flag
C++20 constexpr default constructor of std::atomic and std::atomic_flagC++20 constexpr default constructor of std::atomic and std::atomic_flag
C++20 constexpr default constructor of std::atomic and std::atomic_flag
 
[C++ 20][P0325R4] std::to_array() 내용 정리.
[C++ 20][P0325R4] std::to_array() 내용 정리.[C++ 20][P0325R4] std::to_array() 내용 정리.
[C++ 20][P0325R4] std::to_array() 내용 정리.
 
C++ 20 Efficient access to std::basic_stringbuf’s buffer
C++ 20 Efficient access to std::basic_stringbuf’s bufferC++ 20 Efficient access to std::basic_stringbuf’s buffer
C++ 20 Efficient access to std::basic_stringbuf’s buffer
 
C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions
 
C++20 Utility functions to implement uses-allocator construction
C++20 Utility functions to implement uses-allocator constructionC++20 Utility functions to implement uses-allocator construction
C++20 Utility functions to implement uses-allocator construction
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
 

C++20 Coroutine

  • 2. Coroutine 코루틴은 자신의 상태를 유지하면서 실행을 일시 정지하거나 재개할 수 있는 함수
  • 3. Coroutine 같은 스레드에서 제어권이 변경 되는 것이기 때문에 동기화 문제가 발생하지 않는다 쓰레드 보다 적은 비용이 든다 코루틴 객체는 힙에 생성이 된다 코루틴 객체의 수명에 유의 해야 한다 구현이 어렵다(C++, 개인적인 생각…)
  • 4. 코루틴을 적용할 수 없는 함수들 가변 인자 일반 return 문을 사용 constexpr, consteval 생성자, 소멸자 main
  • 5. 추가된 키워드 co_await 표현식 : 재개 될 때까지 일시 중지 std::size_t n = co_await socket.async_read_some(buffer(data)); co_yield 표현식 : 값을 반환하고 일시 중지 while (true) co_yield n++; co_return 문 : 값을 반환하고 끝낸다 co_return 7;
  • 6. 구현시 필요한 것들 promise "코루틴 내부"에서 관리 되는 객체. 코루틴의 결과나 예외를 이 객체를 통해 호출자에게 전달 하는 용도로 사용 코루틴 핸들 "코루틴 외부"에서 관리 되는 객체. 코루틴을 resume하거나 코루틴 프레임을 제거 할 때 사용 코루틴 프레임 "힙 메모리 영역"에 할당 되는 코루틴 상태를 나타내는 객체
  • 7. promise 아래의 멤버 함수 중 일부를 구현해야한다 구현한 함수는 컴파일러가 자동으로 호출한다
  • 8. 코루틴 핸들 promise_type이라는 내부 형식을 정의하고 있어야한다 직접 정의하거나 std::coroutine_traits를 Generator로 특수화한 std::coroutine_traits<Generator>를 public 형식 멤버 promise_type으로 두어도 된다.
  • 9. 코루틴 프레임 약속 객체, 코루인 인수들의 복사본, 정지 시점을 나타내는 객체, 내부의 지역 변수 등으로 구성됨 대기 가능 객체 코루틴이 일시정지 중인지 아닌지 판정 대기자 객체 대기 가능 객체가 종료 혹은 일시 정지 되길 기다리는 객체 co_await 연산자를 정의하거나 대기 가능 객체를 대기자 객체로 변환해야 한다
  • 10. 대기 가능 객체 Awaitable 콘셉트를 충족해야 함 정의 되어있는 std:: suspend_always 와 std::suspend_never 타입을 사용해도 된다
  • 11.
  • 14. 예제 코드 - 호출 순서