Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how are pthreads on linux seen by scheduler

I've a question regarding pthread implementation on Linux.

Suppose a process has 5 threads. Now how does the scheduler sees these threads (or doesnt see at all). e.g. When scheduler is invoked, does it only schedule the main process, and then its the onus of the main process to schedule between each of its thread.

Or is it the other way, that scheduler schedules each thread as if it is a separate process.

like image 520
Aman Jain Avatar asked Oct 23 '10 15:10

Aman Jain


2 Answers

For modern Linux (NPTL pthread implementation), the scheduler schedules threads, a thread is considered a "Light-weight process". pthread_create is implemented in terms of the clone system call.

like image 182
Logan Capaldo Avatar answered Oct 02 '22 14:10

Logan Capaldo


Linux schedules every thread as if it is a Process with scope as PTHREAD_SCOPE_SYSTEM. The nptl implementation can utilize multiple CPUs.

like image 20
ultimate cause Avatar answered Oct 02 '22 13:10

ultimate cause