Environment
OS: Linux version 6.8.0-59-generic (buildd@lcy02-amd64-117) (x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #61~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:03:15 UTC 2
CPU: AMD Ryzen 7 7700
GPU: RTX 4060Ti
Install nvidia-driver
Issac Sim need to work with nvidia-driver.
Search the available drivers with this command:
May 10, 2025・Contributed by
TLDR
This article implements simple thread-safe counter in C++, and benchmark the speedup. Concepts like data race and mutex granularity are discussed. Codes can be found at github/ThreadSafeCounter.
Pre-requisistes
This article assumes reader understanding on basic usage of C++ threads. If you are not familiar with it, feel free to check my article about Chapter 2 Managing Threads
Introduction
We will start with a non thread-safe version, then proceed to a thread-safe version. Finally, we will try to improve the performance of the thread-safe version.
All implementations have following public methods:
May 07, 2025・Contributed by
This article will set up following tools to develop with C++ 20 in VSCode. My Ubuntu version is 22.04.
gcc 13.1.0 / g++ 13.1.0
clang-format
C/C++ Settings
C/C++ Advanced Lint
GCC
The default gcc on Ubuntu is only at 11, which is not suitable if you want to use C++ >=20 features like std::format.
Apr 29, 2025・Contributed by
Disclaimer
This is my personal notes of the C++ Concurrency in Action, Second Edition book. Most ideas come from the book.
Basic Usage
Normally, we start a thread in C++ by std::thread(work_func, arg1) and then wait for it to complete with join. If we don't call join, the main thread will complete before the t thread, and t will be handled by OS. The example below also shows how to pass arguments to thread by value. The integer num is copied to the thread's own address space.
#include <thread>
#include <iostream>
void work_func(int num)
Apr 27, 2025・Contributed by