
C++11 threads tutorial  - octopus
http://solarianprogrammer.com/2012/02/27/cpp-11-thread-tutorial-part-2/
======
tim_h
Is C++ usage on the decline? I've used a lot of different languages, but I've
never had the occasion to learn C++. I work in web search and we tend to use
interpreted languages. The argument is that Java or C# is much easier to
write/maintain and that we can make up for performance shortcomings by scaling
out.

~~~
octopus
_Is C++ usage on the decline?_

No it is not. C++11 is a modern programming language that lets you harness
every bit of power from your computer.

From a productivity point of view I think Java and C# are as verbose as modern
C++. In the end it really depends on what kind of application you develop, for
web development you can be a few orders of magnitude more productive than in
C++ if you use Python or Ruby. For number crunching nothing beats Fortran.

You should chose your tools (programming language, compiler, OS etc.) based on
what you know and on the application domain.

~~~
tim_h
I wasn't suggesting that that C++ is somehow outdated or inferior. I'm just
wondering if the percent usage of C++ is declining with respect to other
languages.

I'm trying to estimate the chance that me not knowing C++ will pose a problem
later in my career. I normally pick up languages quickly, but the C++ learning
curve seems a bit steeper, both in terms of language nuances and libraries. So
my normal approach of "wait until I need it" may not work that well.

~~~
cornedpig
This is a difficult question. If the number of C++ developers is growing, but
at a slower rate than the number of total developers, is that a decline?

------
jbarham
For C++, that's actually not too bad. Now try creating 100,000 threads with
synchronized communication. In Go it's trivial:

    
    
    		$ cat goroutines.go 
    		package main
    
    		import (
    			"flag"
    			"fmt"
    		)
    
    		var n *int = flag.Int("n", 100000, "thread count")
    
    		func thread(x int, result chan int) {
    			result <- x
    		}
    
    		func main() {
    			flag.Parse()
    
    			results := make(chan int)
    			for i := 0; i < *n; i++ {
    				go thread(i, results)
    			}
    			for i := 0; i < *n; i++ {
    				fmt.Println(<-results)
    			}
    		}
    		$ time ./goroutines | tail
    		99990
    		99991
    		99992
    		99993
    		99994
    		99995
    		99996
    		99997
    		99998
    		99999
    
    		real	0m0.723s
    		user	0m0.396s
    		sys	0m0.840s
    

<http://weekly.golang.org/doc/effective_go.html#concurrency>

~~~
ramy_d
I feel like your comment ignores what languages are for and what people
looking for a c++11 tutorial on threading already know.

You might think an equally trivial example with erlang is in order, but it
totally marginalizes why anyone chooses to write with any given language in
the first place.

