1 // Written by David Schima:
2 // http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=103563
4 // Modified by Leandro Lucarella:
5 // * Removed initial "pause"
6 // * Removed performance counter
7 // * Adapted to D1/Tango
9 // Compiled with: -O -inline -release
11 // Timing with affinity for all 4 CPUs: 28390 milliseconds
12 // Timing with affinity for only 1 CPU: 533 milliseconds
14 // More about contention killing multi-core:
16 // import std.stdio, std.perf, core.thread;
19 // writeln("Set affinity, then press enter.");
22 // auto pc = new PerformanceCounter;
26 // auto threads = new Thread[nThreads];
27 // foreach(ref thread; threads) {
28 // thread = new Thread(&doStuff);
32 // foreach(thread; threads) {
37 // writeln(pc.milliseconds);
41 // foreach(i; 0..1_000_000) {
46 // Timing with affinity for all CPUs: 20772 ms.
47 // Timing with affinity for 1 CPU: 156 ms.
49 // Post on using spin locks in the GC to avoid contention:
50 // http://www.digitalmars.com/d/archives/digitalmars/D/More_on_GC_Spinlocks_80485.html
52 import tango.core.Thread;
55 enum { nThreads = 4 };
56 auto threads = new Thread[nThreads];
57 foreach(ref thread; threads) {
58 thread = new Thread(&doAppending);
62 foreach(thread; threads)
68 for (size_t i = 0; i < 1_000_000; i++)