C++ Multi Threading Part 4: Why You Should Use std::jthread in Modern C++
Автор: arisaif
Загружено: 2025-05-22
Просмотров: 625
Learn why std::jthread is one of the most important additions to C++20's multithreading toolbox. In this video, we walk through its automatic join behavior, built-in cancellation via stop_token, and how it compares to std::thread. If you've ever dealt with std::terminate() from an unjoined thread or struggled with safe shutdown, this video is for you.
🔹 Auto-join: std::jthread safely joins in its destructor
🔹 Stop token: Built-in cooperative cancellation mechanism
🔹 No more polling hacks: Replaces fragile loops and futures
🔹 RAII safety: Clean thread lifecycle management
🔹 Real examples: Exception-safe shutdown, parallel sum, consumer/producer with cancellation
We’ll also cover:
Common pitfalls when using std::jthread
Comparison to std::thread, std::atomic, and condition_variable
How stop_callback can cleanly wake waiting threads
Perfect for C++ developers upgrading to modern, structured concurrency with C++20.
📌 Full code examples included.
📘 Requires C++20 or newer.
🔔 Subscribe for more clean, modern C++ explanations.
You can download and code with me using this link:
https://github.com/ourarash/multithre...
You can run the code either using Bazel or gcc/g++.
This is my fourth video on C++ Multithreading.
Link to Part 1: • Learn C++ Multi Threading in 20 Minutes
Link to Part 2: • C++ Multi Threading Part 2: Mutex And Cond...
Link to Part 3: • C++ Multi Threading Part 3: Atomic Variabl...
-----------------------------------------------------
See my other videos on:
Bazel Tutorial for C++: • Bazel Tutorial for C++ in 30 Minutes
Ultimate Tips on Tech and Coding Job Interviews: • Ultimate Tips on Tech and Coding Job Inter...
Google Test and Mock Platform, Complete Tutorial: • Google Test and Mock Platform, Complete Tu...
-----------------------------------------------------
Keep in touch with me:
/ ourarash
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: