Conversation
…nd simplifying water boiling simulation
오류 수정 from /usr/include/c++/14/stop_token:39,
from /usr/include/c++/14/thread:42,
from CoroutinePractice.cpp:7:
/usr/include/c++/14/bits/atomic_base.h:103:3: note: candidate: ‘constexpr std::memory_order std::operator|(memory_order, __memory_order_modifier)’
103 | operator|(memory_order __m, __memory_order_modifier __mod) noexcept
| ^~~~~~~~
/usr/include/c++/14/bits/atomic_base.h:103:26: note: no known conversion for argument 1 from ‘std::generator<std::expected<int, BrewingError> >’ to ‘std::memory_order’
103 | operator|(memory_order __m, __memory_order_modifier __mod) noexcept
| ~~~~~~~~~~~~~^~~
./run.sh: line 2: ./CoroutinePractice: No such file or directory컴파일 오류의 원인은 GCC 14 컴파일과 실행을 확인했습니다. 변경 사항 적용함. |
Output=== [PROJECT CAFFEINE-FLOW] INITIALIZING PIPELINE ===
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #1
[Success] Consumed Espresso Unit: 1
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #2
[Success] Consumed Espresso Unit: 2
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #3
[Success] Consumed Espresso Unit: 3
[CRITICAL ERROR] Grinder on fire! Evacuating the office.
=== [PROJECT CAFFEINE-FLOW] SHUTTING DOWN SAFELY ===코드 설명이 코드는 generator가 값을 하나씩 지연 생성하고,
현재 출력이 3잔에서 멈춘 것처럼 보이지만, 다음 generator 요청에서 참고로 지금의 |
…chronous water boiling
|
비동기식 적용=== [PROJECT CAFFEINE-FLOW] INITIALIZING PIPELINE ===
[Main] Brewing runs asynchronously; main can continue working.
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #1
[Success] Consumed Espresso Unit: 1
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #2
[Success] Consumed Espresso Unit: 2
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #3
[Success] Consumed Espresso Unit: 3
[CRITICAL ERROR] Grinder on fire! Evacuating the office.
=== [PROJECT CAFFEINE-FLOW] SHUTTING DOWN SAFELY ===
출력에서 변경 사항 적용함. |
…put synchronization
…es in main function
동기식/비동기식 비교=== [PROJECT CAFFEINE-FLOW] INITIALIZING PIPELINE ===
=== SYNCHRONOUS BREW ===
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #1
[Success] Consumed Espresso Unit: 1
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #2
[Success] Consumed Espresso Unit: 2
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #3
[Success] Consumed Espresso Unit: 3
[Synchronous] 3 cups completed in 3.00 seconds.
=== ASYNCHRONOUS BREW ===
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #2
[Success] Consumed Espresso Unit: 2
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #1
[Success] Consumed Espresso Unit: 1
[Hardware] Water successfully boiled to 95°C!
[Barista] Pouring Espresso Cup #3
[Success] Consumed Espresso Unit: 3
[Asynchronous] 3 cups completed in 1.00 seconds.
=== [PROJECT CAFFEINE-FLOW] SHUTTING DOWN SAFELY ===df9b433세 작업을 모두 시작한 뒤 완료를 기다리도록 바꿨고, 각 물 끓이기에 1초 지연을 적용했습니다. 비동기 출력 순서는 작업 스케줄링에 따라 달라질 수 있습니다. 전체 실행 시간은 동기 기준 측정도 포함해 약 4초입니다. 68e7e20
변경 사항 적용함. |
…output readability
출력 결과 수정 : 빈 행 추가
|
코드 설명이 코드는 동기식 방식과 coroutine 기반 비동기식을 나란히 실행해 비교하는 예제입니다. 핵심은 C++20/23에서 추가된 것 C++20은 coroutine의 언어 기능인 C++23에는 이 코드의 비동기 흐름
따라서 동기식 코드는 1초씩 세 번 기다려 약 3초가 걸리고, 비동기식은 세 작업을 겹쳐 진행해 약 1초가 걸립니다. 비동기 작업의 완료 순서와 출력 순서는 스케줄링에 따라 달라질 수 있습니다. 주의할 점 여기서 비동기 처리를 실제로 실행하는 부분은 또한 |
…ling, task management, and brewing functions
독스트링/주석 작성
GCC 14 컴파일을 확인했습니다. 변경 사항 적용함. |
문서화 /
|
Study : Coroutine With or Without Generator이 코드에서는 generator 없이도 비동기 처리가 가능하고, 작업의 목적만 보면 그 편이 더 단순합니다. 두 방식의 역할이 다릅니다.
현재 예제는 컵 세 잔의 작업을 시작하고 완료를 기다리는 구조라서 generator가 필수는 아닙니다. generator를 추가한다면 컵 번호나 주문 목록을 순차적으로 공급하는 역할은 할 수 있지만, 그 자체로 작업을 병렬 실행하거나 비동기로 만들어주지는 않습니다. 오히려 비동기 실행과 값 생성이라는 두 책임이 더해져 예제가 복잡해질 수 있습니다. 다만 학습 목적이 “coroutine과 generator를 함께 써보기”라면 둘을 조합할 수 있습니다. generator가 컵 번호들을 현재 방식의 주의점도 있습니다. 비동기 동작은 coroutine 문법만으로 생기는 게 아니라, |
C++로 비동기 프로그램 작성이 어려운 이유기본적인 그럼에도 불구하고 개발자들이 "C++ 비동기 프로그래밍은 어렵다, 런타임이 없어서 번거롭다"라고 입을 모아 말하는 진짜 이유는, 단일 코루틴의 ## 1.
|
C++20 이전의 비동기 프로그래밍C++20에 코루틴이 도입되기 전, C++ 개발자들이 비동기 프로그래밍을 하던 방식은 "지옥의 콜백(Callback Hell)" 혹은 "무거운 스레드 남발"과의 싸움이었습니다. 파이썬의 ## 1.
|
Output