0

I have a Segmentation fault in my multithreaded application that is becoming a headache. It looks like the problem is being generated in a usleep call. I tried to replace it with nanosleep but it persists. It also appears near to a sem_timedwait call.

I compile with gcc and -lpthread option.

Might this be the cause of the segmentation fault? What could be the reason?

funkadelic
  • 311
  • 1
  • 2
  • 10
  • 2
    More likely that the root of the segmentation fault is an error in your code. Until you show your code, it's imposible to say what's wrong. – Dan Kruchinin Nov 15 '11 at 16:52
  • This question doesn't really fit the SO question/answer format. Try coming up with a more specific question. – N_A Nov 15 '11 at 16:52
  • If you want help debugging your code, you need to post a MINIMAL COMPLETE example. It needs to be small so it fits in a post, but also needs to be complete, showing everything necessary to reproduce the problem. Without that, you won't get any useful help. – Chris Dodd Nov 15 '11 at 17:01
  • I'd like to post the problematic code, but the application is huge and multithreaded and I cannot locate it. I work with an embedded device and I have no possibility to make real-time debugging :( Just wanted to know if usleep/nanosleep/sem_timedwait is a possibility... – funkadelic Nov 15 '11 at 17:05
  • @mydog Whilst a specific answer cannot be given, general guidance can be offered. Indeed the Q asks for just that. Sometimes you need to tailor the response to the level of detail available in the Q. – David Heffernan Nov 15 '11 at 18:45
  • @DavidHeffernan There are lots of better ways to get a more detailed answer to that question than asking a new one on SO including simply finding old questions - http://stackoverflow.com/questions/3718998/methodology-for-fixing-segmentation-faults-in-c and http://stackoverflow.com/questions/77522/multithreaded-debugger – N_A Nov 15 '11 at 22:08

1 Answers1

3

Segmentation fault means that you are accessing memory which you don't have rights to. It is usually due to a bounds error on an array or a stale pointer, e.g. access after free. Calling sleep seems exceedingly unlikely to be related to this unless you are using sleep as a synchronization tool! You could use valgrind to track down your error.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490