Recently been discussed in the forum to see multi-core, then,
Associated with multi-core and multithreading so what's it?
I did an experiment,
AMD Athlon (tm) 64 X2 Dual Core
Ubuntu i386 / kernel: linux 2.6.32-25
1.Main function in the time to start a thread, a CPU 100%
2.Main function in the start when the two threads, 2 CPU 100%
3.Main function in a thread, but start 2 times, and the effect of two similar
Conclusion: The system will automatically deploy CPU, and found that the system will automatically use two CPU utilization in the smaller CPU.
That is, multi-core CPU running multi-threaded program, if the program does not specify when the CPU information, OS CPU core will be responsible for scheduling and management of multi-core CPU does not need to consider OS scheduling. But if they want to balance the load of multi-core CPU, when you create the thread, you can specify the thread's CPU affinity (CPU Affinity), using as linux c api: sched_setaffinity, windows c api: SetProcessAffinityMask, SetThreadAffinityMask function, can interfere with OS of thread scheduling, balance CPU load.
In the core cpu running on the specified thread (c / c + +): http://www.cppblog.com/Khan/archive/2009/12/29/104384.html
JAVA so it?
In the JRockit JVM Management API you can at least Suggest the Process affinity. Not sure if IT is respected on the OS you're running. See http://e-docs.bea.com/jrockit/releases/R27/javadoc/ manapi / Docs / COM / bea / JVM / JVM.html # suggestProcessAffinity (java.util.Collection) for more Information.
JVM jvm = JVMFactory.getJVM ();
List cpus = new ArrayList ();
for (Iterator it = JVMFactory.getJVM (). getProcessAffinity (). iterator (); it.hasNext ();)
CPU cpu = (CPU) it.next ();
You can find JRockit here.
I used taskset on my 4 cpu machine, and by using:
taskset-pc 0 java net.tilialacus.BusyThreads
I gbound all threads to cpu 0. (BusyThreads just runs a few threads with
However, if I started the process first, then I have to bind all threads
manually to the CPU. Using ps-eLf I could list all threads (10 or so)
and I could bind each of them separately. I didn't find a way for
taskset to climb the process / thread tree automatically.