Multi-threading in Mac OS X

M

murali

Hi,
I would like to know how multi-threading works on a
multi-processor machine(G4 power MAC).Do special commands have to be
given access multiple processors?
Thanks,
Murali.
 
S

Sean Burke

Hi,
I would like to know how multi-threading works on a
multi-processor machine(G4 power MAC).Do special commands have to be
given access multiple processors?
Thanks,
Murali.

Depends what programming language your are using.
Assuming java, use the Thread class to create a
new thread. In C/C++/Objective-C, use pthreads.

-SEan
 
D

Danny Woods

Hi,
I would like to know how multi-threading works on a
multi-processor machine(G4 power MAC).Do special commands have to be
given access multiple processors?

Generally, the Java VM will try to balance out the threads it has across
the available processors. It won't split a single thread, so running a
single-threaded Java application on a multi-processor machine is a bit of a
waste of time (the background threads, like the finalizer and the garbage
collector, don't make enough use of a processor's time to be called
'effective use').

From the programmers' perspective, all that needs to be done is ensure
that you have enough threads in your system to make use of what's
available. If you're trying to make optimal use of the available processing
power, Runtime.availableProcessors() will let you know what you have to
work with.

Finally, threading issues can bite you on a multi-processor system, so your
thread interaction must be *very* careful. Remember, now you have *true*
concurrency, with instructions executing side-by-side on the different
processors. Java's built in synchronization mechanisms will help here.

Hope that helps,

Danny.
 
R

Roedy Green

Generally, the Java VM will try to balance out the threads it has across
the available processors.

If you are using native threads, the VM has no say in such decisions,
other than by the priority you set on each thread. Allocating to CPUs
is the OS's problem. Further a thread does not need to stay allocated
to the same CPU throughout its lifetime.

A better approximation to reality is that every task ready to go in is
a queue. As cpus become available, they take the top task and run
with it. It works sort of like a barbershop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top