Time of thread vs process in windows?
I need to chose between a process with 2 threads or a 2 processes with one thread on windows. I am intresting in the time slice. Windows running threads so context switch will be in either case. What I want to know if the time it runs each of the thread in the 2 cases开发者_JAVA技巧 will be the same? Thanks.
Windows schedules threads, so yes, they will be the same.
The Windows scheduler doesn't care which process a thread is from, just what the thread priorities are. If you have a single process with threads T1 and T2 vs a pair of processes P1 (equivalent to T1) and P2 (equivalent to T2) then there is no difference from the scheduler's point of view, provided P1 and T1 have the same priority, as do P2 and T2.
However, Windows gives a priority boost to the current foreground application, so threads in the foreground process will get more or longer time slices than those in background processes.
If your application is subject to this priority boost, then dividing it into separate processes means that only one process benefits from the boost. If you use multiple threads within a process then all threads benefit from the boost.
精彩评论