You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Crash in loadlocale()

I am porting a C++ app from Windows to OSX (10.6.8) and I'm getting a seemingly

thread related crash in std::ostream::operator<<(). The function loadlocale crashes with

Exception Type: EXC_BAD_ACCESS (SIGBUS)

Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000004


Any ideas why this might be happening?


Here are the relevant stack traces.


Thread 5 Crashed:

0 libSystem.B.dylib 0x9824ab85 __numeric_load_locale + 133

1 libSystem.B.dylib 0x98178599 loadlocale + 308

2 libstdc++.6.dylib 0x9aa14205 std::__convert_from_v(int* const&, char*, int, char const*, ...) + 143

3 libstdc++.6.dylib 0x9aa0db5e std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const + 192

4 libstdc++.6.dylib 0x9aa0ddb4 std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const + 64

5 libstdc++.6.dylib 0x9aa08583 std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const + 59

6 libstdc++.6.dylib 0x9aa169dd std::ostream& std::ostream::_M_insert<double>(double) + 181

7 libstdc++.6.dylib 0x9aa16a76 std::ostream::operator<<(float) + 28

...


Thread 6:

0 libSystem.B.dylib 0x98148e0a open$NOCANCEL$UNIX2003 + 10

1 libSystem.B.dylib 0x9824b46b __part_load_locale + 204

2 libSystem.B.dylib 0x9824acf0 __numeric_load_locale + 496

3 libSystem.B.dylib 0x98178599 loadlocale + 308

4 libstdc++.6.dylib 0x9aa1423e std::__convert_from_v(int* const&, char*, int, char const*, ...) + 200

5 libstdc++.6.dylib 0x9aa0db5e std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const + 192

6 libstdc++.6.dylib 0x9aa0ddb4 std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const + 64

7 libstdc++.6.dylib 0x9aa08583 std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const + 59

8 libstdc++.6.dylib 0x9aa169dd std::ostream& std::ostream::_M_insert<double>(double) + 181


Glenn

Posted on Nov 9, 2011 7:36 PM

Reply
2 replies

Oct 16, 2013 1:18 PM in response to glennra

A Google search led me to this discussion. I am encountering a similar problem under similar circumstances: I have C++ code that originated on Windows that I am trying to make run on the Mac. I am getting intermittent crashes in __numeric_load_locale, apparently when two separate threads try invoking std::ostream::operator <<(double) at the same time. (The call stacks above indicate that the original poster is also outputting a double value to a standard stream. In my case the stream in question is a std::wstringstream and we are trying to convert the double to a wide string.)


I believe, based largely on circumstantial evidence, that the crash is due to a bug in the GNU C++ library (libstdc++). I experimentally updated a version of my project to use the LLVM C++ library (libc++) and could not reproduce the crash. Unfortunately, my project is still targeting Snow Leopard, on which libc++ is not supported, so we are stuck with libstdc++ for the time being. As a workaround, I'm going to try protecting our string conversion function with a critical section (it's part of a custom logging package built on an open source JSON library) to avoid the problem.

Crash in loadlocale()

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.