C++11 concurrency bug since update 3 ? RRS feed

  • Question

  • Hey,

    I am using c++11 threading libraries with visual studio 2012 ( phone and windows 8 ) editions. Ever since I installed update 3 all my programs started crashing periodically. After few hours of investigating I came to the conclusion that connect bug 762560 is back. The forum doesn't allow me to post the actual link, but basically std::condition_variable::wait_for crashes at random moments. The following code reproduces it:

    // Concurrency bug in Microsoft Visual C++ 2011
    #include <mutex>
    #include <thread>
    #include <condition_variable>
    #include <vector>
    struct WaitForConditionInThreads
    	std::mutex mutex;
    	std::condition_variable condition;
    	void run(int threads)
    		std::vector<std::thread> thread_pool(threads);
    		for(auto & i : thread_pool)
    			i = std::thread(&WaitForConditionInThreads::thread_fn, this);
    		for(auto & i : thread_pool)
    	void thread_fn()
    		int count=100;
    		std::unique_lock<std::mutex> lock(mutex);
    			condition.wait_for(lock, std::chrono::milliseconds(1));
    int main()
    	WaitForConditionInThreads w;
    	for(;;) w.run(16);

    Can anyone confirm it? Also if that's the case whats the alternative? Good ol' WaitForSingleObject and similar can't be used in RT (right?) so what should I do? Revert to update 2?


    Sunday, July 14, 2013 8:45 AM


All replies