GCC's behaviour with std::async(std::launch::async) vs. Clang's behaviour

c++, c++11, clang, gcc, policy

Solution

The behavior is within spec, even if it's not what you desire. If you don't specify a launch policy, it is taken to be `async|deferred`, which means it is up to the implementation to decide which. GCC happens to always pick `deferred` if given a choice.

Problem

Does anyone has experience with the rather new `std::async`? We are currently implementing a parallel file parser, which reads a file chunk and passes this chunk to an async function. Using Clang (v3.0) this way works really fine with the default `std::async` policies (implementation dependent). On a two core machine, it fires up to 4 threads what works really well. But with GCC (v4.7), the file reading thread does not spawn any new threads, making the program in the end completely sequential. Using `std::launch::async`, both versions are pretty much doing the same (what should be the case). Does anyone know the status of the current of GCC's c++11 threading capabilities? Or might this be an error in our implementation? Short code: ``` while (readNewChunk()) { Chunk &chunk = fileReader_.getChunk(); //reading the file ChunkLoader *chunkLoader = new ChunkLoader(); auto ftr = std::async(std::launch::async, &ChunkLoader::createDictionaries, chunkLoader); dictCreationFutures_.push_back(std::move(ftr)); } ```

Original source