Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Using thread support provided by c++0x on cygwin. (http://www.velocityreviews.com/forums/t743472-using-thread-support-provided-by-c-0x-on-cygwin.html)

mangesh sawant 02-13-2011 06:07 AM

Using thread support provided by c++0x on cygwin.
 
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??



Saeed Amrollahi 02-13-2011 08:33 AM

Re: Using thread support provided by c++0x on cygwin.
 
On Feb 13, 9:07*am, mangesh sawant <m.v.saw...@gmail.com> wrote:
> 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

Andy Venikov 02-13-2011 09:12 PM

Re: Using thread support provided by c++0x on cygwin.
 
On 02/13/2011 01:07 AM, mangesh sawant wrote:
> 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.


All times are GMT. The time now is 04:08 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.