Re: Question about multi-processing, multi-threading...
Re: Question about multi-processing, multi-threading...
- Subject: Re: Question about multi-processing, multi-threading...
- From: Chris Hanson <email@hidden>
- Date: Wed, 21 Jan 2004 12:23:28 -0600
On Jan 21, 2004, at 10:38 AM, Thierry Bucco wrote:
I have written a little C program who execute an infinite loop.
When I launch process viewer, I can see that my 2 processors are busy.
(60%, 40%).
Right, it's using 100% of 200% available CPU.
I was thinking that if an application was not multi threaded (like my
little exemple), the task was rans on only 1 procesor, it seems that
it's wrong.
Yes, that's incorrect. The task's thread will run on only one
processor *at a time*. When the thread is preempted, and has to wait
before being run again, the operating system can schedule it on any
available processor. This is what symmetric multiprocessing means.
But If I change my source code, to execute 2 infinite loops in a forked
process, my processors are very busy (100%, 100%).
Right, it's using 200% of 200% available CPU now.
Is there a way to force a thread to run on the second processor ?
There's no such thing as "the first processor" or "the second
processor" in a symmetric multiprocessing system. The processors are
considered the same by everything beyond the boot process, which
processor a thread is scheduled on depends entirely on which processor
is available when the scheduling occurs.
Note that in Mach, there's not really any such thing as a "process" in
the Unix sense. There are tasks, which are collections of resources (a
memory map, file descriptors etc.) and there are threads, which are
flows of control (a program counter, a stack, a register set, etc.). A
Unix process is a task with at least one thread.
Threads are the actual unit of scheduling in Mach, so if you run a task
with two threads and there are other threads in other tasks running at
the same time, your task's threads may still be scheduled sequentially
rather than simultaneously. All threads compete for processor
resources whenever they're runnable, they're not segregated by task.
(At least not classically; I don't know if that's still entirely true
in Darwin.)
Could you give me some informations about scheduling on OS X ?
There's always the Darwin source code, that'll give you the most
accurate picture possible because that's what's running on your
machine. Also, there have been some books about Mach where you could
get a general overview of how it all fits together which might be
useful before reading the Darwin source.
-- Chris
--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.