I am having a hard time understanding the difference between User threads vs Kernel threads.
What I have understood until now is (kindly correct me if I am wrong, and we are discussing everything in the context of Linux) -
There's nothing like a User thread anymore; the notion that a User thread is created in user space and is mapped to a kernel-level thread to get executed is pretty much outdated.
By Kernel thread, I mean a thread that is scheduled by the Kernel, and the thread I make in my program using std::thread ( func, arguments ) is a Kernel thread in the above sense, and it does not need to map to anyone to get scheduled and get executed.
The C++ standard does not specify how to implement the threads obtained with std::thread. That is an implementation decision of the C++ standard library that you are using. On an operating system that has kernel threads, the library might map C++ stdlib threads to kernel threads. Or it might not. The C++ specification does not allow for passing tuning parameters into thread creation in the way that the pthread_ functions do. So, unless there are language extensions at work, you cannot influence any decisions that the library makes.
However, in practical terms, Ted Lyngmo and I are unaware of any C++ library implementation on Linux that does not pass through to pthreads and return a pthread_t from std::thread::native_handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With