Note that there are some explanatory texts on larger screens.

plurals
  1. POSeg Fault when using std::string on an embedded Linux platform
    primarykey
    data
    text
    <p>I have been working for a couple of days on a problem with my application running on an embedded Arm Linux platform. Unfortunately the platform precludes me from using any of the usual useful tools for finding the exact issue. When the same code is run on the PC running Linux, I get no such error.</p> <p>In the sample below, I can reliably reproduce the problem by uncommenting the string, list or vector lines. Leaving them commented results in the application running to completion. I expect that something is corrupting the heap, but I cannot see what? The program will run for a few seconds before giving a segmentation fault.</p> <p>The code is compiled using a arm-linux cross compiler:</p> <pre><code>arm-linux-g++ -Wall -otest fault.cpp -ldl -lpthread arm-linux-strip test </code></pre> <p>Any ideas greatly appreciated.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;vector&gt; #include &lt;list&gt; #include &lt;string&gt; using namespace std; ///////////////////////////////////////////////////////////////////////////// class TestSeg { static pthread_mutex_t _logLock; public: TestSeg() { } ~TestSeg() { } static void* TestThread( void *arg ) { int i = 0; while ( i++ &lt; 10000 ) { printf( "%d\n", i ); WriteBad( "Function" ); } pthread_exit( NULL ); } static void WriteBad( const char* sFunction ) { pthread_mutex_lock( &amp;_logLock ); printf( "%s\n", sFunction ); //string sKiller; // &lt;----------------------------------Bad //list&lt;char&gt; killer; // &lt;----------------------------------Bad //vector&lt;char&gt; killer; // &lt;----------------------------------Bad pthread_mutex_unlock( &amp;_logLock ); return; } void RunTest() { int threads = 100; pthread_t _rx_thread[threads]; for ( int i = 0 ; i &lt; threads ; i++ ) { pthread_create( &amp;_rx_thread[i], NULL, TestThread, NULL ); } for ( int i = 0 ; i &lt; threads ; i++ ) { pthread_join( _rx_thread[i], NULL ); } } }; pthread_mutex_t TestSeg::_logLock = PTHREAD_MUTEX_INITIALIZER; int main( int argc, char *argv[] ) { TestSeg seg; seg.RunTest(); pthread_exit( NULL ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload