Kalyan Ghosh
Kalyan Ghosh

Reputation: 493

Threads inside a Process

Processes get CPU time as managed by the OS process scheduler. Since threads run in parallel within a single process, does this mean that a process's CPU time is further distributed(sliced) among threads? Or can the scheduler directly distribute CPU time among threads bypassing the parent process?

Upvotes: 0

Views: 172

Answers (3)

Jerry Coffin
Jerry Coffin

Reputation: 490118

I suspect the answer varies with the OS. On Windows, the process is not merely bypassed, but completely ignored -- all the scheduler deals with is threads. Processes are relevant only to the degree that all non-kernel threads do have to belong to some process, and every process has to contain at least one thread.

Upvotes: 3

Patrick
Patrick

Reputation: 23619

The threads are run/scheduled by the operating system and therefore they get their own CPU time. The process CPU time is just the sum of the CPU times of all the threads in the process.

If you want your process to schedule the tasks itself, you should use fibers (Windows). These are a kind of threads but they are not scheduled by the OS. The process should handle the scheduling of fibers itself.

Upvotes: 2

Related Questions