Like Tree2Likes

std::thread leads to Abort

This is a discussion on std::thread leads to Abort within the C++ Programming forums, part of the General Programming Boards category; Apparently if you don't have "-pthread", it would just link in some kind of a stub, that just crashes your ...

  1. #16
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Apparently if you don't have "-pthread", it would just link in some kind of a stub, that just crashes your program when you call any std::thread function.

  2. #17
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    t.cpp is the little program above.
    Code:
    $ gcc -ggdb -std=c++0x -lstdc++ -pthread -o t t.cpp
    $ ./t
    terminate called without an active exception
    Aborted

  3. #18
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Order matters for linking.

  4. #19
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    ... just tell me what to use, please.

    "$ gcc -pthread -std=c++0x -lstdc++ -o t t.cpp" doesn't fix it.

  5. #20
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    I don't know... I'm on Windows right now.

    I only remember I had to play with the order of arguments.

  6. #21
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    On an unrelated (or maybe related) side note, why are you compiling .cpp with gcc and not g++?

  7. #22
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    I just SSHed into my box. Without -pthread it segfaults, and with -pthread it aborts. So it's probably something totally unrelated.

  8. #23
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Works if I add
    Code:
    t.join();
    User Name: likes this.

  9. #24
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    gcc is just a wrapper for all the g* compilers. It calls the appropriate compiler based on file suffix. It's just a habit to use gcc and let it decide which g* compiler should be used.

  10. #25
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Come now, cyberfish, I shouldn't be the one to tell you this... but quadruple posting? You know there is an edit button, right?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Quote Originally Posted by cyberfish View Post
    Works if I add
    Code:
    t.join();
    Your right... It also works if you add t.detach(). Aren't threads supposed to detach themselves upon deconstruction?

  12. #27
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Tehe .

    I found the problem, it's in the code.

    Thread is still running when the destructor gets called, and it doesn't like that.
    Code:
    (gdb) r
    Starting program: /tmp/a.out
    [Thread debugging using libthread_db enabled]
    [New Thread 0xb7d29b70 (LWP 17495)]
    terminate called without an active exception
    [Thread 0xb7d29b70 (LWP 17495) exited]
    
    Program received signal SIGABRT, Aborted.
    0xf57fe416 in __kernel_vsyscall ()
    (gdb) bt
    #0  0xf57fe416 in __kernel_vsyscall ()
    #1  0xb7d55651 in raise () from /lib/tls/i686/cmov/libc.so.6
    #2  0xb7d58a82 in abort () from /lib/tls/i686/cmov/libc.so.6
    #3  0xb7fa352f in __gnu_cxx::__verbose_terminate_handler() ()
       from /usr/lib/libstdc++.so.6
    #4  0xb7fa1465 in ?? () from /usr/lib/libstdc++.so.6
    #5  0xb7fa14a2 in std::terminate() () from /usr/lib/libstdc++.so.6
    #6  0x08048a50 in ~thread (this=0xbffff7dc, __in_chrg=<value optimized out>)
        at /usr/include/c++/4.4/thread:138
    #7  0x080489dd in main () at a.cpp:9

  13. #28
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Quote Originally Posted by cyberfish View Post
    Tehe .

    I found the problem, it's in the code.

    Thread is still running when the destructor gets called, and it doesn't like that.
    That most definitely sounds like a bug.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Does the standard say anything about that?

    It looks pretty deliberate in the header file -
    Code:
        ~thread()
        {
          if (joinable())
            std::terminate();
        }
    In /usr/include/c++/4.4/thread line 138.

  15. #30
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    It boggles your mind, but according to...
    c++ - thread destructors in C++0x vs boost - Stack Overflow
    ...it is the correct behavior.

    In other words, we're stuck with a useless thread object -_-
    Bye, bye RAII...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird typo leads to interesting result... what does it mean?
    By pollypocket4eva in forum C++ Programming
    Replies: 4
    Last Post: 06-17-2010, 03:30 AM
  2. abort() causes a segfault
    By JFonseka in forum C Programming
    Replies: 12
    Last Post: 04-16-2008, 01:40 AM
  3. abort()
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 02-22-2008, 03:11 AM
  4. Abort Procedure
    By incognito in forum Windows Programming
    Replies: 5
    Last Post: 01-02-2004, 08:49 PM
  5. Western society leads to unsatisfaction
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 08-06-2003, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21