C++ 11 std::thread strange behavior
问题 I am experimenting a bit with std::thread and C++11, and I am encountering strange behaviour. Please have a look at the following code: #include <cstdlib> #include <thread> #include <vector> #include <iostream> void thread_sum_up(const size_t n, size_t& count) { size_t i; for (i = 0; i < n; ++i); count = i; } class A { public: A(const size_t x) : x_(x) {} size_t sum_up(const size_t num_threads) const { size_t i; std::vector<std::thread> threads; std::vector<size_t> data_vector; for (i = 0; i