Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Using thread support provided by c++0x on cygwin.

Reply
Thread Tools

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

 
 
mangesh sawant
Guest
Posts: n/a
 
      02-13-2011
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??


 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      02-13-2011
On Feb 13, 9:07*am, mangesh sawant <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Andy Venikov
Guest
Posts: n/a
 
      02-13-2011
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is malloc() function provided in <stdlib.h> thread-safe? climber.cui@gmail.com C Programming 33 04-28-2008 03:49 AM
Computer Support Forums : Provided By User: DlSoftware DlSoftware Computer Support 44 04-19-2007 05:52 PM
Is headless support provided? =?Utf-8?B?U3VzYW5uZSBTdMO2aHI=?= Windows 64bit 5 10-26-2006 04:37 PM
Using Tracing provided by Logging and Instrrumentation Appln block in Web Application Samy ASP .Net 0 11-10-2005 08:31 PM
Re: DOT NET frame work provided session management using SQL SERVER MS News \(MS ILM\) ASP .Net 0 08-26-2003 12:56 AM



Advertisments