Segmentation fault only when running on multi-core?

Sounds like you're using Linux (you mention pthreads). Have you considered running valgrind?

Up vote 3 down vote favorite share g+ share fb share tw.

I am using a c++ library that is meant to be multi-threaded and the number of working threads can be set using a variable. The library uses pthreads. The problem appears when I run the application ,that is provided as a test of library, on a quad-core machine using 3 threads or more.

The application exits with a segmentation fault runtime error. When I try to insert some tracing "cout"s in some parts of library, the problem is solved and application finishes normally. When running on single-core machine, no matter what number of threads are used, the application finishes normally.

How can I figure out where the problem seam from? Is it a kind of synchronization error? How can I find it?

Is there any tool I can use too check the code? C++ multithreading segmentation-fault multicore link|improve this question asked Nov 17 '09 at 6:29Navid4117 56% accept rate.

3 From your description it seems to be a racing condition, where one of the threads is most probably trying to access memory that is not initialized yet by another thread. You might want to try reproing this under the debugger and looking at the call stack at the failure point. – Franci Penov Nov 17 '09 at 6:32 I really have no idea where the failure point is, because in debug mode the problem does not appear.

– Navid Nov 17 '09 at 6:36 some compilers in the debugging mode initializes the variables by their default values so it may not happen in the debugging mode – Ahmed Said Nov 17 '09 at 6:43 2 You can include debugging symbols when optimizing and can attach a debugger regardless of either of those. "Debug mode" is a misnomer. – Roger Pate Nov 17 '09 at 6:54 1 When you get a SEGFAULT you can get the system to dump a core of the program that can then be loaded by the debugger.

Different system uses different methods to signal the need for a core file. But usually it is as simple as setting an environment variable. Check your system documentation for details.

– Loki Astari Nov 17 '09 at 8:08.

Sounds like you're using Linux (you mention pthreads). Have you considered running valgrind? Valgrind has tools for checking for data race conditions (helgrind) and memory problems (memcheck).

Valgrind may be to find such an error in debug mode without needing to produce the crash that release mode produces.

I've used helgrind. It suggests some errors as race conditions in sections that are run in serial sections of code also it indicates some identical errors in parallel parts as shown below, but I don't understand what it means. -------------------------------------------- ==28556== This conflicts with a previous read of size 4 by thread #6 ==28556== at 0x806A3ED: Population::GaSortedGroup::GetAt(int) const (SortedGroup.

H:181) .....(order of method calls) – Navid Nov 17 '09 at 7:59 A race condition is where you have two or more threads looking at the same bit of data at (potentially) the same time. Generally shared mutable data should be protected by a mutex so you can't (for example) get one thread reading data as another thread updates it. This can give you stale data and lead to problems.

– Jeff Foster Nov 17 '09 at 9:52.

Some general debugging recommendations. Make sure your build has symbols (compile with -g). This option is orthogonal to other build options (i.e.

The decision to build with symbols is independent of the optimization level). Once you have symbols, take a close look at the call stack of where the seg fault occurs. To do this, first make sure your environment is configured to generate core files (ulimit -c unlimited) and then after the crash, load the program/core in the debugger (gdb /path/to/prog /path/to/core).

Once you know what part of your code is causing the crash, that should give you a better idea of what is going wrong.

I know nothing about what core is. And I don't know /path/to/core. Could you explain more detailed please?

– Navid Nov 17 '09 at 7:52 Well, you will soon discover 'gdb' then :) – Matthieu M. Nov 17 '09 at 13:57.

You are running into a race condition. Where multiple threads are interacting on the same resource. There are a whole host of possible culprits, but without the source anything we say is a guess.

You want to create a core file; then debug the application with the core file. This will set up the debugger to the state of the application at the point it crashed. This will allow you to examin the variables/registers etc. How to do this will very depending on your system.

A quick Google revealed this: codeguru.com/forum/archive/index.php/t-2... Hope this helps.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions