LWN.net Logo

A look at C++14, part 1

A look at C++14, part 1

Posted Mar 30, 2013 3:36 UTC (Sat) by elanthis (guest, #6227)
In reply to: A look at C++14, part 1 by simlo
Parent article: A look at C++14, part 1

Threads - when invisible - are super important. No, most programs don't _need_ them, but I rather enjoy when the program I'm running on my modern 8-core desktop does its operations nearly instantly rather than making me wait because at most it's using ~12% of my CPU.


(Log in to post comments)

A look at C++14, part 1

Posted Mar 30, 2013 10:38 UTC (Sat) by simlo (subscriber, #10866) [Link]

Most likely the program is not waiting to get CPU - it is waiting for blocking IO. If you have 8 cores, the OS will schedule the other programs to the other CPUs.
Threading is most of the time a hack around blocking API calls. It is very rare that a normal desktop program actually have CPU work for more than one CPU.
And then you forget the cost in programming time and runtime of locking overhead: A single threaded program does not need atomic operations, which can be quite expensive on a multi cored platform. If, for instance, a program uses reference counting (std::shared_ptr), these operations have to be atomic. If you know the program is single threaded, that overhead is not needed. That kind of overhead might make the single threaded program run faster than the multi threaded, which very often can not use all 8 CPUs anyway due to lock contention.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds