system scope vs. process scope

John Baldwin jhb at freebsd.org
Mon Aug 7 14:51:24 UTC 2006


On Friday 04 August 2006 20:06, David Xu wrote:
> On Friday 04 August 2006 23:34, John Baldwin wrote:
> 
> > Suppose you have a system with 2 processes.  One process is single-threaded
> > and is CPU bound.  The other process has 2 threads both of which are also
> > CPU bound.  If the threads in the second process are PTHREAD_SCOPE_SYSTEM,
> > then each thread will get 33% of the CPU.  If the threads in the second
> > process are PTHREAD_SCOPE_PROCESS, then the each process will get 50% of
> > the CPU. The second process will then use its own algorithm to split it's
> > 50% of the CPU up between it's two threads.  If it divides it evenly, then
> > each of its' threads will end up with 25% of the CPU whereas the thread for
> > the first process has 50% of the CPU.  The idea for this is that if you
> > have a system with several single-threaded processes and one process with
> > 1000 threads, you don't want that process to starve out all the other
> > processes.
> >
> I can make my application fork 800 processes and starve out all the other
> user.

Yes, but then you aren't sharing the same address space, which your
application might need if it wants to do threading. :)  And, your statement
aside, I believe the above is why the difference exists.  Your statement is
more about the usefulness of the distinction, not about the justification
for when it was created.

-- 
John Baldwin


More information about the freebsd-threads mailing list