listings-Chap29-README.md
Listings of Chap29.docx
This is linked summary of the listings. You can also view it on one page.
- Listing 29.1: How to start a thread.
- Book: lst-0001-book.cpp
- Godbolt: lst-0001-godb.cpp, https://godbolt.org/z/qnadYPWh1
- GodboltId:nPGY47r4K
- Book: lst-0003-book.cpp
- Godbolt: lst-0003-godb.cpp, https://godbolt.org/z/nPGY47r4K
- Listing 29.2: With “stop_token”, the outside world communicates into the thread.
- Book: lst-0004-book.cpp
- Godbolt: lst-0004-godb.cpp, https://godbolt.org/z/6cqd7Tsae
- GodboltId:Tzs93MzfK
- Book: lst-0005-book.cpp
- Godbolt: lst-0005-godb.cpp, https://godbolt.org/z/Tzs93MzfK
- GodboltId:E49on6zn3
- Book: lst-0006-book.cpp
- Godbolt: lst-0006-godb.cpp, https://godbolt.org/z/E49on6zn3
- GodboltId:T4c1GnjY4
- Book: lst-0007-book.cpp
- Godbolt: lst-0007-godb.cpp, https://godbolt.org/z/T4c1GnjY4
- GodboltId:8TdzEGf3d
- Book: lst-0008-book.cpp
- Godbolt: lst-0008-godb.cpp, https://godbolt.org/z/8TdzEGf3d
- Listing 29.3: Add parameters to the thread function in the constructor.
- Book: lst-0009-book.cpp
- Godbolt: lst-0009-godb.cpp, https://godbolt.org/z/bMdrWrd4c
- Listing 29.4: Parameters are copied into the thread.
- Book: lst-0010-book.cpp
- Godbolt: lst-0010-godb.cpp, https://godbolt.org/z/fbnbKzrs1
- Listing 29.5: Use caution with raw pointers as parameters.
- Book: lst-0011-book.cpp
- Godbolt: lst-0011-godb.cpp, https://godbolt.org/z/hvq5dbzde
- Listing 29.6: Forcing a reference with ref.
- Book: lst-0012-book.cpp
- Godbolt: lst-0012-godb.cpp, https://godbolt.org/z/GnsWYvecv
- Listing 29.7: Using “move” to transfer inputs to the thread.
- Book: lst-0013-book.cpp
- Godbolt: lst-0013-godb.cpp, https://godbolt.org/z/Pjzqsv9nz
- Listing 29.8: Returning a thread.
- Book: lst-0014-book.cpp
- Godbolt: lst-0014-godb.cpp, https://godbolt.org/z/Kv84eb96E
- Listing 29.9: Moving a thread.
- Book: lst-0015-book.cpp
- Godbolt: lst-0015-godb.cpp, https://godbolt.org/z/8cMTrEWz6
- Listing 29.10: Threads in containers.
- Book: lst-0016-book.cpp
- Godbolt: lst-0016-godb.cpp, https://godbolt.org/z/YrEPnYMaP
- Listing 29.11: Finding out the hardware concurrency.
- Book: lst-0019-book.cpp
- Godbolt: lst-0019-godb.cpp, https://godbolt.org/z/zojG68dWq
- Listing 29.12: Each thread has an identifier.
- Book: lst-0020-book.cpp
- Godbolt: lst-0020-godb.cpp, https://godbolt.org/z/TM6c7cdss
- Listing 29.13: A classic data race.
- Book: lst-0021-book.cpp
- Godbolt: lst-0021-godb.cpp, https://godbolt.org/z/7GEs9a4n6
- Listing 29.14: Benign data races are also undefined.
- Book: lst-0022-book.cpp
- Godbolt: lst-0022-godb.cpp, https://godbolt.org/z/v3b6sxEab
- Listing 29.15: Latches can count down and wait.
- Book: lst-0023-book.cpp
- Godbolt: lst-0023-godb.cpp, https://godbolt.org/z/rrfn4d5WP
- Listing 29.16: A barrier waits for a specific number of threads.
- Book: lst-0024-book.cpp
- Godbolt: lst-0024-godb.cpp, https://godbolt.org/z/515dMo9Kx
- Listing 29.17: A mutex together with a simple lock.
- Book: lst-0025-book.cpp
- Godbolt: lst-0025-godb.cpp, https://godbolt.org/z/3fz5a4vYv
- Listing 29.18: The interface to a multithreaded stack.
- Book: lst-0026-book.cpp
- Godbolt: lst-0026-godb.cpp, https://godbolt.org/z/4j7njd763
- Listing 29.19: Problematic code for the “MxStack”.
- Book: lst-0027-book.cpp
- Godbolt: lst-0027-godb.cpp, https://godbolt.org/z/1boeTMMvf
- Listing 29.20: A possible way two threads could execute the previous code.
- Book: lst-0028-book.cpp
- Listing 29.21: A very simple thread-safe stack.
- Book: lst-0029-book.cpp
- Godbolt: lst-0029-godb.cpp, https://godbolt.org/z/vcb9qP8jK
- Listing 29.22: “swap” for “MxStack”.
- Book: lst-0032-book.cpp
- Godbolt: lst-0032-godb.cpp, https://godbolt.org/z/9PMcz1cqP
- Listing 29.23: Mutexes can be transferred.
- Book: lst-0033-book.cpp
- Godbolt: lst-0033-godb.cpp, https://godbolt.org/z/e7rraPGx4
- Listing 29.24: Late initialization with a single thread.
- Book: lst-0034-book.cpp
- Godbolt: lst-0034-godb.cpp, https://godbolt.org/z/T7vehq58b
- Listing 29.25: Late initialization with multiple threads.
- Book: lst-0035-book.cpp
- Godbolt: lst-0035-godb.cpp, https://godbolt.org/z/3vcnzfqfM
- Listing 29.26: Late initialization can also be useful within a thread.
- Book: lst-0036-book.cpp
- Godbolt: lst-0036-godb.cpp, https://godbolt.org/z/TcsrefEPh
- Listing 29.27: Precautions are necessary when a mutex needs to be locked multiple times.
- Book: lst-0037-book.cpp
- Godbolt: lst-0037-godb.cpp, https://godbolt.org/z/KPaPoh4Gn
- Listing 29.28: Memory only for the current thread.
- Book: lst-0038-book.cpp
- Godbolt: lst-0038-godb.cpp, https://godbolt.org/z/1j8W7GjTf
- Listing 29.29: Two threads communicate via a condition variable.
- Book: lst-0040-book.cpp
- Godbolt: lst-0040-godb.cpp, https://godbolt.org/z/c9x6xT8dr
- Listing 29.30: “async” can easily initiate asynchronous computations.
- Book: lst-0045-book.cpp
- Godbolt: lst-0045-godb.cpp, https://godbolt.org/z/Gh9Y5srd7
- Listing 29.31: It is okay not to retrieve a result.
- Book: lst-0046-book.cpp
- Godbolt: lst-0046-godb.cpp, https://godbolt.org/z/7Mea1Y3Mn
- Listing 29.32: How to enforce deferred execution.
- Book: lst-0047-book.cpp
- Godbolt: lst-0047-godb.cpp, https://godbolt.org/z/P9MjGe6Mn
- Listing 29.33: Waiting for a certain time with “async”.
- Book: lst-0048-book.cpp
- Godbolt: lst-0048-godb.cpp, https://godbolt.org/z/o9oYrvMcj
- Listing 29.34: Waiting for a lock with a “timed_mutex”.
- Book: lst-0049-book.cpp
- Godbolt: lst-0049-godb.cpp, https://godbolt.org/z/xzY8hj9oP
- Listing 29.35: Exceptions only arrive at “get” in the outer thread.
- Book: lst-0050-book.cpp
- Godbolt: lst-0050-godb.cpp, https://godbolt.org/z/rYM9xqsGa
- Listing 29.36: Only the “get” needs to be encapsulated in “try”.
- Book: lst-0051-book.cpp
- Godbolt: lst-0051-godb.cpp, https://godbolt.org/z/1WG5arvWT
- Listing 29.37: A “future” and “promise” working together.
- Book: lst-0053-book.cpp
- Godbolt: lst-0053-godb.cpp, https://godbolt.org/z/7E1E6aezE
- Listing 29.38: Preparing a packaged task for later execution.
- Book: lst-0054-book.cpp
- Godbolt: lst-0054-godb.cpp, https://godbolt.org/z/9s94nbrx3
- Listing 29.39: Provide a packaged task with arguments later.
- Book: lst-0055-book.cpp
- Godbolt: lst-0055-godb.cpp, https://godbolt.org/z/bq1hn5rjo
- Listing 29.40: How to determine if the operations are lock-free.
- Book: lst-0056-book.cpp
- Godbolt: lst-0056-godb.cpp, https://godbolt.org/z/dG318o9ez
- Listing 29.41: The “SpinlockMutex” class prevents sleeping while waiting.
- Book: lst-0057-book.cpp
- Godbolt: lst-0057-godb.cpp, https://godbolt.org/z/EnjPr5r76
- Listing 29.42: Your coroutine returns a “generator”.
- Book: lst-0058-book.cpp
- Godbolt: lst-0058-godb.cpp, https://godbolt.org/z/Gfazq6GE7
- Listing 29.43: A simple example of a coroutine return type with its “promise_type”.
- Book: lst-0059-book.cpp
- Godbolt: lst-0059-godb.cpp, https://godbolt.org/z/8enx43Ksb