4 ms·
Is a std::thread a thin wrapper around pthreads on Linux?
by saagarjha 7y ago
Is a std::thread a thin wrapper around pthreads on Linux?
- fwsgonzo 7y agoYep. And all the serialization is futex wait/wake.
- foo101 7y agoA related question if anyone knows good answers here. What programming languages' de-facto thread implementations are not wrappers around pthreads? I think Go has its own thread implementation? Or am I mistaken?
- saagarjha 7y agoRight, Go uses green (userspace) threads.
- daurnimator 7y agozig optionally uses pthreads (depending on if you link against libc or not)
- signa11 7y agoerlang has its own process/thread implementation with, iirc, 64b per process.
- toast0 7y agoThe docs [1] say: > A newly spawned Erlang process uses 309 words of memory in the non-SMP emulator without HiPE support. (SMP support and HiPE support both add to this size.) And a word is the native register size, so 4 or 8 bytes these days, so fairly small, but not 64 bytes small. [1] http://erlang.org/doc/efficiency_guide/processes.html http://erlang.org/doc/efficiency_guide/processes.html
- ghostwriter 7y agoGHC Haskell's runtime has a "default" light-weight thread system (forkIO) that schedules logical threads on the available operating system threads and parallelises them across available CPUs: - https://wiki.haskell.org/Parallelism#Multicore_GHC https://wiki.haskell.org/Parallelism#Multicore_GHC - https://stackoverflow.com/a/41485705 https://stackoverflow.com/a/41485705 - https://www.aosabook.org/en/posa/warp.html https://www.aosabook.org/en/posa/warp.html
- deleted 7y ago[deleted]
- pjmlp 7y agoJava does not specify the actual threading model, so you can get green threads (user space) or red threads (kernel threads). The upcoming Project Loom, intends to make it so that green threads become the default (aka virtual threads on Loom), but you can still ask for kernel threads, given that is what most JVM implementations have converged into.
- signa11 7y agoyes.
- abjKT26nO8 7y agoWith the caveat that the destructor crashes your program if you neither join nor explicitly detach the thread.
- ncmncm 7y agoBut, don't detach the thread.
- pjmlp 7y agoC++20 has apparently a fix for it with std::jthread, though. With all possible the learnings from Java, .NET, Erlang, TBB, Concurrency Runtime, and yet ISO C++ did not manage to get a proper concurrency story, and it full of traps like the one you mention. Another one is std::async, which might actually be synchronous, depending on a set of factors.