One thing that really clicked for me when learning system programming on Linux: std::thread is not “magic”. Under the hood, it often relies on native OS threads — and on Linux, that typically means pthread. So the abstraction looks like this: C++ code → std::thread → pthread → OS threads That changed how I see modern C++. std::thread is not replacing low-level threading — it is giving you a safer, portable interface on top of it. And that is why: you get RAII type safety and cleaner APIs without losing performance. The real takeaway : When you use std::thread, you are still using system threads — just with a better interface. Curious: Did you start with pthread or directly with std::thread? #cpp #cplusplus #multithreading #concurrency #linux #softwareengineering #programming
I started with pthread in C and it's still all I use! This post makes me want to explore std::thread and see the difference in practice.
But compare to cross platform vs POSIX is much safer
pthreads are bad because they have unnecessary overhead; they shine because they are standard. Exceptions stink. I can't stand the lack of visibility in pthreads regarding windows semaphores. I want threads that state exactly why they stopped.
std::thread are terrible. They lack basic configuration features such as priority and stack size. A parallel system without priorities, seriously? Calling a third-party library, getting a stack overflow, and realizing you can't adjust the thread stack size, seriously? std::thread are unusable in serious parallel applications. And please don't mention native_handle. You can get it only after the thread is started, when it's too late to configure the thread's attributes.
I have my own threading abstractions that pad over pthread and Win32 threading differences which I like much better than std::thread and std::async. I'll do without the STL layer.
Recently learned about Java virtual threads which are managed by JVM itself. This gives a feasibility to spawn multiple threads without impacting os threads. Similar functionality we have in C++ with boost Fiber. Try to dig deep into it. The transition from pthreads to std::thread to boost thread and co-routines in C++ is astounding. Simpler, safe and without impacting performance.
This is not just for threads, it for everything like as simple as cout , which essentially calls write system call in Linux
Use std::jthread. No more forgetting to join.
I started with pthreads, still use them for C code. Otherwise std::thread with C++ code.
Most of the system calls in C++ are wrappers class. std::thread class is wrapped around createthread in windows, same class is wrapped as pthread in linux.