[Qt-interest] Threads
BRM
bm_witness at yahoo.com
Wed Jun 23 16:14:49 CEST 2010
----- Original Message ----
> From: Thiago Macieira <thiago at kde.org>
> Em Quarta-feira 23. Junho 2010, às 06.38.53, Mandeep Sandhu escreveu:
> >> Doh! That's not quite right... but it's usually right.
> >> pthreads is POSIX, and somewhat implementation independent.
> >> The threads are supplied with
> your libc. Most these days are shipping
> >> NPTL. NPTL is kernel threads. LinuxThreads is user-space threads
> (IIRC). Most every distro is using NPTL these days.
> IMO, NPTL != kernel threads.
> In Linux each thread is directly seen
> by the kernel as a schedulable
> entity. But threads are still run in user
> space unlike linux kernel
> threads which run in the kernel context.
> That is correct. But that might not be the distinction that the
> OP was going after.
> Kernel threads are those which the kernel itself
> schedules. Like you said yourself, each thread in Linux is directly
> scheduled by the kernel, so they are kernel threads.
> User threads are
> those in which the userspace does the scheduling, usually in-process and
> cooperative. At one point, the userspace code decides to context-switch on
> its own to another thread and resume executing it.
Depends on the implementation. You'd have to look at the guts of NPTL to verify, but it could change from one version to another as well if they reworked it. You really shouldn't need to care. (If you do, there's likely something wrong with your model.)
A user-space thread could be associated with a kernel space thread.
Or the user-space thread could be scheduled by the kernel and still remain in user-space.
I believe there are some algorithms that allow the kernel to allocate the thread's time slices,
but it then allocates that time slice against the processes entire time slice.
Either way, the threads run in user-space context regardless of how they are scheduled,
as you can only instantiate kernel space context threads from within the kernel.
Linux tries to do as much as possible in user-space.
BRM
More information about the Qt-interest-old
mailing list