[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threads



Michael Day wrote:

> The threading discussion appears to have reached a vague concensus that
> threads are useful for modularizing or reducing program complexity, though
> often inefficient when used for this purpose. However one working thread
> per processor on an SMP system can certainly be more efficient than a
> single thread or process labouring away on only one cpu.

Agreed.

> This leads to a somewhat anticlimactic question, what is a good portable way
> of determining the number of processors? I know of a Win32 API call to
> achieve this, and the data can be munged out of /proc on linux I assume,
> but to support an arbitrary operating system, what is The Right Thing? I
> have been unable to find much libgtop documentation, is this library
> suitable for determining this kind of system information? Or should the
> process keep spawning threads until it notices efficiency beginning to
> decrease? :)

Quake3 uses a rather portable way: it has the user tell Quake if the
machine is SMP or not. :-)

Seriously, I have no idea. Most platforms have a way of determining
this, but they are all unportable. I guess this would go under "platform
dependent code", along with sound device and framebuffer access.

-- 
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi