I recently wanted to get involved in C++0x (Native, OS independent thread support?! Heck yes I want that!), and it seemed as though my compiler supports it. So, I added it in Code::Blocks, under Settings >> Compiler and debugger.. >> Global Compiler Settings >> checked "Have g++ follow the comming C++0x ISO C++ language standard [-std=c++0x]". But, whenever I try to run this simple program;

#include <iostream>
#include <thread>

using namespace std;

void threadFunc();

int main()
{
   thread t(threadFunc);
}

void threadFunc()
{
    cout << "hello" << endl;
}

Which _should_ work under C++0x, it keeps giving me the error; "error: 'thread' was not declared in this scope", and "error: expected ';' before 't'". While I know full it _should_ work.

Help?

GCC does not fully support the multithreading libraries or language features yet. See this. The main problem is that the threading libraries make most sense when the language features for concurrent programming are also available, and these are probably the hardest of the new language features to implement.

I recommend you use the Boost.Thread library in the mean time, it's almost identical to the C++0x threading library.

If you are interested in using C++0x, I also recommend you keep your GCC compiler up-to-date, I mean, really up-to-date. Right now, 4.6.2 and 4.7.0 are good versions for C++0x support, but you pretty much have to compile them from source (I do that every month or so). You might also want to check out my tutorials here and here.

GCC does not fully support the multithreading libraries or language features yet. See this. The main problem is that the threading libraries make most sense when the language features for concurrent programming are also available, and these are probably the hardest of the new language features to implement.

I recommend you use the Boost.Thread library in the mean time, it's almost identical to the C++0x threading library.

If you are interested in using C++0x, I also recommend you keep your GCC compiler up-to-date, I mean, really up-to-date. Right now, 4.6.2 and 4.7.0 are good versions for C++0x support, but you pretty much have to compile them from source (I do that every month or so). You might also want to check out my tutorials here and here.

I'll take a look at it... But this is for a project I'm working on (build a basic Operating System), so I need _native_ , OS independent functions.

>>so I need _native_ , OS independent functions.

If you expect that the C++0x thread library will be native code, you are greatly mistaken. Threading models are a feature provided by the OS (e.g. doing multi-threading on Linux or Windows is very different, whatever library you use). If you are implementing a basic operating system, then making a threading library is one of your tasks, you won't find a native library for threading that doesn't require having an operating system of some kind running. The C++0x threading library, like the Boost.Thread library, are just OS-independent in the sense that the way you use the library is exactly the same from one OS to another, but the underlying implementation relies on the OS features and kernel calls.

You do understand that compilers you can use to compile an operating system to run on a computer natively have libraries that are very different from typical standard library implementations, and are more limited, because most of the things that you take for granted are accomplished by the OS kernel (like dynamic memory allocation, threading, file IO, any other kind of IO, etc.). Standard C/C++ library implementations are provided for an OS and rely on that OS to provide the features it provides, so these are not _native_ functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.