I understand that Linux scheduler schedules threads, not processes, but I do not understand how do threads within a process get scheduled.
Say I have a process P1 with threads T1,T2 and a process P2 with threads T1,T2,T3. Now the scheduler has to schedule 5 tasks. P1T1, P1T2, P2T1, P2T2 and P2T3. If the scheduler picks up P1T1 and then picks up P2T2, this will lead to process context switching, which defeats the purpose of threading. How does the scheduler work in this case ?