views:

76

answers:

2

i am using visual c++ 2010 can i run this code?

what should i add to visual studio?

+4  A: 

Visual C++ 2010 does not provide the C++0x thread support or atomics libraries.

If you want to use that code in Visual C++ 2010, you'll need to use a third-party implementation of those libraries. One option is just::thread; it's not free, but I have a copy and am quite pleased with it.

Alternatively, you can use another cross-platform threads library like Boost.Thread or OpenThreads or one of the native Windows threads libraries. Any of these options will probably require changes to the code in order to run.

James McNellis
And a free kinda-equivalent is Boost.Thread and Boost.Atomic (unofficial).
GMan
@GMan: True; one major thing that Boost.Thread is (to the best of my knowledge) missing is an equivalent to `std::async`, which is the greatest thing since the creation of the destructor.
James McNellis
Yeah, it does have futures though, so it's not too far out of reach.
GMan
A: 

VC++ supports special embedded syntax OpenMP (http://msdn.microsoft.com/en-us/library/tt15eb9t(VS.80).aspx) - note, that g++ is also suports it, so you can get cross platform code.

Dewfy
how is the question related to OpenMP?
CharlesB
@CharlesB - OpenMP embeds to language level all primitives expected by multithreading and the way to parallelize execution: atomic, barrier, critical and parallel at last. What wrong with the answer? It is relates to VS++, it answers how to provide multithreading without third-party library.
Dewfy
@Dewfy well the code posted in the question is related to c++0x's thread library, which OpenMP doesn't implement, thus my comment.
CharlesB
@CharlesB - look at answer by James McNellis: "Visual C++ 2010 does not provide the C++0x thread support or atomics libraries." Which means that no way to run this code. This leads us to search some work around - either use third party (James McNellis already shows this solution), or use already on board functionality. OpenMP is provided with VC++. In both ways code should be rewritten.
Dewfy