[RESOLVED] gcc 4.5.1 C++0x thread support
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] gcc 4.5.1 C++0x thread support

  1. #1
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    [RESOLVED] gcc 4.5.1 C++0x thread support

    Hi,

    I am trying to compile gcc 4.5.1 for cygwin with support for C++0x threads.
    However, the resulting gcc does not recognize the -pthread option.
    My configure command is:
    Code:
    ./configure --enable-bootstrap --enable-shared --enable-shared-libgcc --with-gnu-ld --enable-languages=c,c++ --enable-libgomp --enable-libssp --enable-threads=posix --with-__thread
    The sample program is:
    Code:
    #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;
    }
    I am compiling a C++ program using
    Code:
    $ gcc -Wall -g -std=c++0x -pthread Trial.cpp
    gcc: unrecognized option '-pthread'
    Trial.cpp: In function `int main()':
    Trial.cpp:21:5: error: `thread' was not declared in this scope
    Trial.cpp:21:12: error: expected `;' before `t'
    Trial.cpp:22:5: error: `t' was not declared in this scope

    Can anybody tell me if there is any option I missed to enable thread support?
    Last edited by rohshall; August 23rd, 2010 at 02:59 AM.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,885

    Re: gcc 4.5.1 C++0x thread support

    According to this page:
    http://gcc.gnu.org/projects/cxx0x.html
    it looks like the gcc support for concurrency is still fairly minimal. I don't think that page covers what's been done with the gcc standard library though.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: gcc 4.5.1 C++0x thread support

    I was unaware that there was a gcc for Windows, I thought it was MinGW. MinGW doesn't come with the pthreads libraries I don't think, you have to get it.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,778

    Re: gcc 4.5.1 C++0x thread support

    "-pthread" should be a synonym for "-pthreads". Try it with an s on the end.

    >> I was unaware that there was a gcc for Windows [other than MinGW]
    It's more "gcc for Cygwin" - which provides a Posix environment on Windows.
    http://www.cygwin.com/

    gg

  5. #5
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: gcc 4.5.1 C++0x thread support

    Thank you all. gcc supports C++0x thread since its 4.3 version
    http://stackoverflow.com/questions/3...in-eclipse-cdt

    I have read a couple of other blogs using gcc with this feature. So, I think I am just making some mistake in configuring the gcc. Unfortunately the gcc binaries that are available for cygwin are old. So, I need to compile from source.

  6. #6
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: gcc 4.5.1 C++0x thread support

    Quote Originally Posted by Codeplug View Post
    "-pthread" should be a synonym for "-pthreads". Try it with an s on the end.
    gg
    I tried it, but that option is also not recognized. I am aware that pthreads is a separate library and I can link using -lpthreads, but this C++0x thread is library separate from the pthreads though it is just a wrapper on that on Posix systems.

  7. #7
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: gcc 4.5.1 C++0x thread support

    I found this link that says cygwin does not support pthread_mutex_timedlock function. So, the C++0x threading support is disabled in cygwin.

    http://stackoverflow.com/questions/3...thread-problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center