Search code examples
multithreadingkernelmulticore

How kernel treats two user level threads?


After reading many threads related material, I'm still confused about the ULT and KLT. How kernel treats two ULT of same process? Can two user level threads of same process run simultaneously on multi core CPU? If yes, is it done by kernel or library function?


Solution

  • Since the Linux version 2.6, the standard implementation is NPTL (Native Posix Thread Library) which assign 1 User level thread to 1 kernel thread (actually Linux "knows" only tasks -not processes neither threads- circa 8kb of kernel memory).

    Just in case of a multi-processor/core machine (CONFIG_SMP defined in the kernel code) one thread may be allocated on any available processor. In Linux any processor has a "run-queue" (which in case of SCHED_NORMAL or SCHED_OTHER a red-black tree data structure is used to contain a list of task ready to run. "Migration" of task between two run-queue is possible.

    I hope this help to clarify!

    _ _

    Kasper.