From: Tony Johansson on
Hi!

One computer with two cores running an application that use only the main
thread will be given time slice
but if this same application use several threads then as I assume will be
given more cpu time because of using additional threads.
I mean for example if you have three threads then you will be given three
time slices.

//Tony


From: Brian Cryer on
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:uHU9x8O8KHA.1760(a)TK2MSFTNGP04.phx.gbl...
> Hi!
>
> One computer with two cores running an application that use only the main
> thread will be given time slice
> but if this same application use several threads then as I assume will be
> given more cpu time because of using additional threads.
> I mean for example if you have three threads then you will be given three
> time slices.

No. Assuming all threads are of equal priority, are CPU bound and ignoring
other processes in the system then the proportion of cpu time that each
thread will receive is inversly proportional to the number of threads.

So, assuming single core (because its easier to illustrate with) then:
with 1 thread it will get 100% of available cpu time.
with 2 threads each will get 50% of available cpu time.
with 3 threads each will get 33% of available cpu time
and so on.

So by adding extra threads you are diluting your CPU resource between them
so each will get less.

What I've said is a little misleading because threads aren't typically of
equal priority, are typically not CPU bound and there are other processes in
the system. So there remain practical reasons why having more threads will
give you improved performance - for example while one thread is reading from
disk (a comparativly slow operation) another can be doing number crunching.

Hope this helps.
--
Brian Cryer
http://www.cryer.co.uk/brian

From: Tony Johansson on
Good explained!

I'm not so used to threads.

//Tony


"Brian Cryer" <not.here(a)localhost> skrev i meddelandet
news:eCr8zfP8KHA.2248(a)TK2MSFTNGP05.phx.gbl...
> "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
> news:uHU9x8O8KHA.1760(a)TK2MSFTNGP04.phx.gbl...
>> Hi!
>>
>> One computer with two cores running an application that use only the main
>> thread will be given time slice
>> but if this same application use several threads then as I assume will be
>> given more cpu time because of using additional threads.
>> I mean for example if you have three threads then you will be given three
>> time slices.
>
> No. Assuming all threads are of equal priority, are CPU bound and ignoring
> other processes in the system then the proportion of cpu time that each
> thread will receive is inversly proportional to the number of threads.
>
> So, assuming single core (because its easier to illustrate with) then:
> with 1 thread it will get 100% of available cpu time.
> with 2 threads each will get 50% of available cpu time.
> with 3 threads each will get 33% of available cpu time
> and so on.
>
> So by adding extra threads you are diluting your CPU resource between them
> so each will get less.
>
> What I've said is a little misleading because threads aren't typically of
> equal priority, are typically not CPU bound and there are other processes
> in the system. So there remain practical reasons why having more threads
> will give you improved performance - for example while one thread is
> reading from disk (a comparativly slow operation) another can be doing
> number crunching.
>
> Hope this helps.
> --
> Brian Cryer
> http://www.cryer.co.uk/brian
>


From: Peter Duniho on
Tony Johansson wrote:
> Hi!
>
> One computer with two cores running an application that use only the main
> thread will be given time slice
> but if this same application use several threads then as I assume will be
> given more cpu time because of using additional threads.
> I mean for example if you have three threads then you will be given three
> time slices.

It really just depends on what else is going on. Brian's reply assumes
that your hypothetical application (process) is already getting 100% of
the CPU with just one thread. So of course with that assumption it
cannot possible get more CPU time by adding threads (and in fact, will
get less _useful_ CPU time because there's overhead in switching from
one thread to another). You can't have more than 100% of the total CPU
time.

But of course that's not a very interesting example, and is trivially
designed to make it impossible to increase the CPU time allocated to the
process.

A more interesting example would be to assume _two_ running processes,
each with one thread, and each consuming as much CPU time is granted it.
In that case, adding threads to one process _does_ increase the amount
of CPU time it gets. Assume we keep one process having just one thread,
and add threads to the other process:

� If the other process has two threads, then it has 2/3rds of the
running threads on the system and so gets 2/3rds of the CPU time

� If it has three threads, then it gets 3/4ths of the CPU time

� If it has four threads, then it gets 4/5ths of the CPU time

� etc.

Every thread that is scheduled to run is given the same time slice
(quantum), and unless it yields the CPU it will use the entire quantum.
So, ignoring other effects (such as priority, i/o, synchronization,
etc. all of which can affect whether a thread gets to run at all, and
for how long), adding threads to one process that is competing with one
or more other processes for the CPU will result in that one process
getting more of the CPU time.

Pete
 | 
Pages: 1
Prev: Newsgroup Server Software
Next: More about threads