Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2008 Jan : threads and cpu load
| Subject: | threads and cpu load |
| Posted by: | "Jens Gruschel" (nospam@thisurldoesnotexist.com) |
| Date: | Wed, 23 Jan 2008 20:23:13 |
Just a theoretical question that just came to my mind: let's say I have
a single threaded task requiring 50% of the cpu load (maybe each second
something has to be done requiring half a second). Assuming no other
heavy work has to be done the cpu usage looks like this:
xx--xx--xx--xx--
cpu load 50%
If I run the same program on a dual core cpu it might look like this:
x---xx-------x-- (1)
-x------xx--x--- (2)
cpu load 25%
Both cores are busy, but never at the same time.
Now I'm rewriting my code, two threads are used instead, which results in:
x---x---x---x--- (1)
x---x---x---x--- (2)
cpu load 25%
The cpu load still is the same, but both cores are used at the same
time, so I think latter approach is better (maybe the clock rate can be
lowered or things like that).
Two questions: Is it right that the latter approach really is better
(assuming there is no overhead by synchronization issues and things like
that)? And: Is there some number telling me that it is better (seems
like the cpu load cannot tell me)?
--
Jens Gruschel
http://www.pegtop.net