C ++ console apps are being written with XCode 6.3 crash

Any code can crash ... while the same code is ok with VC ++.

This is just one of them:

#include <iostream>
#include <string>
#include <thread>
#include <mutex>

using namespace std;

int main()
{
    mutex lock;

    auto loop = [&lock](string name) {

        for (int i = 0; i < 100; ++i)
        {
            lock.lock();

            cout << name << ' ' << i << endl;

            lock.unlock();

            this_thread::sleep_for(10ms);
        }
    };

    auto a = thread(loop, "A");
    auto b = thread(loop, "B");

    a.join();
    b.join();

    return 0;
}

      

The application is launched when the thread starts with a constructor tuple

, referring to some null pointer.

And if I put the libc ++ source code in my project instead of referencing dylib the problem goes away ...

I've rarely written C ++ console applications on Mac OS X before. I wonder if this is my problem or an apple.


Call stack at the point of failure:

With this char const*&&

(and not char const *

) nothing is referenced.

#0  0x0000000100000c7b in std::__1::__tuple_leaf<1ul, char const*, false>::__tuple_leaf<char const*, void>(char const*&&) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:222
#1  0x0000000100000c77 in std::__1::__tuple_impl<std::__1::__tuple_indices<0ul, 1ul>, main::$_0, char const*>::__tuple_impl<0ul, 1ul, main::$_0, char const*, main::$_0, char const*>(std::__1::__tuple_indices<0ul, 1ul>, std::__1::__tuple_types<main::$_0, char const*>, std::__1::__tuple_indices<>, std::__1::__tuple_types<>, main::$_0&&, char const*&&) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:416
#2  0x0000000100000c41 in std::__1::__tuple_impl<std::__1::__tuple_indices<0ul, 1ul>, main::$_0, char const*>::__tuple_impl<0ul, 1ul, main::$_0, char const*, main::$_0, char const*>(std::__1::__tuple_indices<0ul, 1ul>, std::__1::__tuple_types<main::$_0, char const*>, std::__1::__tuple_indices<>, std::__1::__tuple_types<>, main::$_0&&, char const*&&) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:416
#3  0x0000000100000c2a in std::__1::tuple<main::$_0, char const*>::tuple<main::$_0, char const*, false>(main::$_0&&, char const*&&) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:569
#4  0x0000000100000bf5 in std::__1::tuple<main::$_0, char const*>::tuple<main::$_0, char const*, false>(main::$_0&&, char const*&&) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:569
#5  0x0000000100000bd2 in std::__1::thread::thread<main::$_0&, char const (&) [2], void>(main::$_0&&&, char const (&&&) [2]) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:352
#6  0x0000000100000ab5 in std::__1::thread::thread<main::$_0&, char const (&) [2], void>(main::$_0&&&, char const (&&&) [2]) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:359
#7  0x0000000100000998 in main at /Users/blue/Documents/_/Test1/Test1/main.cpp:27
#8  0x00007fff863545c9 in start ()

      

The funny thing is, the code runs in release mode. Although some other code works in debug mode, but not in release mode.

+3


source to share





All Articles