1

Do threads belonging to the same process share the time alloted to the process or the time alloted to the process depends on the number of threads in the process....i.e a time slot is alloted to each thread by CPU...???

Mishthi
  • 1,101
  • 3
  • 12
  • 13
  • Link below will answer your question (For Linux OS): In one sentence, each thread gets its own time slice. For full answer: https://stackoverflow.com/questions/15601155/does-linux-schedule-a-process-or-a-thread – andreyk2 Hohlov Feb 06 '21 at 17:16

2 Answers2

0

A general answer doesn't exist since it depends on the policy adopted by any specific OS.

Three common choices are:

  • 1 to 1, every thread has it's own schedulable entity
  • N to 1, all threads of the same process aren't seen by the OS kernel, so just the whole process is scheduled (bad for multi-threading but good for legacy, they are somewhat similar to green threads)
  • N to M, N threads are mapped to M schedulable entities (this is an hybrid approach that tries to be a compromise but it raises complexity of the scheduling)

More detailed explaination here.

Jack
  • 131,802
  • 30
  • 241
  • 343
  • HOW the time is allocated doesn't depend on how the threads are managed with respect to processes but by the scheduling policy adopted by the OS. eg: if it's round-robin and 1 to 1 then every thread receives the same quantum of time, if instead it's N to 1 then all the threads of the same process receive just one quantum and so on. – Jack Dec 03 '10 at 14:57
0

For Windows, there's good documentation about how threads are selected to run here. Thread priority is a combination of per-process and per-thread information.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • This is a very good question, can any body answer how it happens in linux, becuase i read linux does not differentiate between thread and process – csavvy Mar 19 '20 at 16:50