Using thread support provided by c++0x on cygwin.

M

mangesh sawant

Hi,

I am trying to compile following code using gcc version "g++ (GCC)
4.3.4 20090804 (release) 1" on cygwin
------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <thread>
using namespace std;

void hello()
{
cout << "Hello Concurrent World!" << endl;
}

int main()
{
cout << "starting" << endl;
thread t(hello);
t.join();
cout << "ending" << endl;
return 0;
}
------------------------------------------------------------------------------------------

When i try to compile this like :
g++ -D_POSIX_TIMEOUTS -D_GLIBCXX__PTHREADS -D_GLIBCXX_HAS_GTHREADS -
enable-auto-import -std=c++0x sample.cpp --lpthread

I get folowing error :

sample.cpp:2:18: error: thread: No such file or directory
sample.cpp: In function `int main()':
sample.cpp:13: error: `thread' was not declared in this scope
sample.cpp:13: error: expected `;' before `t'
sample.cpp:14: error: `t' was not declared in this scope

Can anyone help with this?? Do I need to have a higher version of
gcc??
 
S

Saeed Amrollahi

Hi,

I am trying to compile following code using gcc version "g++ (GCC)
4.3.4 20090804 (release) 1"  on cygwin
------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <thread>
using namespace std;

void hello()
{
 cout << "Hello Concurrent World!" << endl;

}

int main()
{
 cout << "starting" << endl;
 thread t(hello);
 t.join();
 cout << "ending" << endl;
 return 0;}

------------------------------------------------------------------------------------------

When i try to compile this like :
g++ -D_POSIX_TIMEOUTS -D_GLIBCXX__PTHREADS -D_GLIBCXX_HAS_GTHREADS -
enable-auto-import -std=c++0x sample.cpp  --lpthread

I get folowing error :

sample.cpp:2:18: error: thread: No such file or directory
sample.cpp: In function `int main()':
sample.cpp:13: error: `thread' was not declared in this scope
sample.cpp:13: error: expected `;' before `t'
sample.cpp:14: error: `t' was not declared in this scope

Can anyone help with this?? Do I need to have  a higher version of
gcc??

Hi

I compiled and ran you program under Suse Linux/g++ 4.5.0 with the
following
command:
g++ -std=c++0x -pthread thread_test.c++ -o thread_test
It's OK and I got output. Indeed the -pthread options is required.
I compiled and ran the program with your command excluded
enable-auto-import and -lpthread (not two dashes) and it is OK too.
Based on the error messages you received, I think
you don't have thread library and you have to install a newer one.
Mine is good, but the newest version of GCC is 4.5.2.

HTH
-- Saeed Amrollahi
 
A

Andy Venikov

Hi,

I am trying to compile following code using gcc version "g++ (GCC)
4.3.4 20090804 (release) 1" on cygwin
------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<thread>
using namespace std;

void hello()
{
cout<< "Hello Concurrent World!"<< endl;
}

int main()
{
cout<< "starting"<< endl;
thread t(hello);
t.join();
cout<< "ending"<< endl;
return 0;
}
------------------------------------------------------------------------------------------

When i try to compile this like :
g++ -D_POSIX_TIMEOUTS -D_GLIBCXX__PTHREADS -D_GLIBCXX_HAS_GTHREADS -
enable-auto-import -std=c++0x sample.cpp --lpthread

I get folowing error :

sample.cpp:2:18: error: thread: No such file or directory
sample.cpp: In function `int main()':
sample.cpp:13: error: `thread' was not declared in this scope
sample.cpp:13: error: expected `;' before `t'
sample.cpp:14: error: `t' was not declared in this scope

Can anyone help with this?? Do I need to have a higher version of
gcc??

As far as I remember 4.3 did not have support for threads yet.
Experimental support was added in 4.4 but not advertised.
In 4.5 has official incomplete support for threads.

HTH,
Andy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top