Apple Open Sources Snow Leopard's Grand Central Dispatch (Apple Insider)
Apple Open Sources Snow Leopard's Grand Central Dispatch (Apple Insider)
Posted Sep 14, 2009 8:19 UTC (Mon) by njs (subscriber, #40338)In reply to: Apple Open Sources Snow Leopard's Grand Central Dispatch (Apple Insider) by nix
Parent article: Apple Open Sources Snow Leopard's Grand Central Dispatch (Apple Insider)
That article tries to justify it with nonsense like "if you have 8 cpus, 6 threads are running, and you start 4 threads, then those 4 threads have to spend all their time on the 2 remaining CPUs", but of course in reality all 10 threads would be scheduled across all 8 cpus, and our program with 4 threads would get a larger share of the total CPU than if it only spawned 2 threads.
If I have a big video transcode running in the background with one thread per cpu, and then I interactively apply a filter in Photoshop, I don't really want that interactive job to politely become sequential rather than step on the batch job's toes. And it's not like anything *bad* will happen if they each spawn 1 thread per CPU and then share.
Obviously if you have enough threads then at some point context switch overhead and cache effects will become overwhelming, but this is just a latency/throughput trade-off -- GCD only avoids context-switch slowdowns because it is willing to decide that some code can run now, and some will have to wait (how does it know which is which?). I already have a rich vocabulary for managing that trade-off (SCHED_IDLE/SCHED_BATCH/nice/cgroups/etc.) without reimplementing my scheduler in userspace...
