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?
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.