Gentlemen, please tell me what the trick can be: a mutex is contained in a global structure, it is normally initialized, normally captured and released by threads, but only a few times ... The cycle in which work with this mutex is identical for all child threads passes valid 3-5 times, when trying to capture another pthread_mutex_lock generates SIGSEGV .

When parsing a dump in gdb, the segmentation error still comes up when accessing pthread_mutex_lock , but I strongly doubt that the problem is in the call. Directly by the debugger and valgrind is not yet close, the addresses that are passed to the function are valid, but an intriguing thing came out - got a variable in the thread stack, looped out its address a couple of times - it changed ... the value of the variable assigned to creating a stream is preserved. Washes someone faced with a similar?

  • In gdb run? - dzhioev
  • @dzhioev, not yet, launch under a stripped-down embedded OS, as soon as you manage to upload gdb there - I will try, while debugging according to the messages of the magazine - margosh
  • Most likely the memory is spoiled. In any static variable (at the addresses next to the mutex) read (), strcmp () or something like that do not do? - avp
  • @avp, yes, this is the most likely reason, I’ll do a dump right now and figure it out, but I’m wondering if something like this could arise from other reasons, for example, when the stack stack overflows, and how to track it - margosh
  • @margosh, you write about a "stripped down embedded OS." Here I find it difficult to talk about the reasons. You are the address of any variable from the thread stack print and compare with the addresses of static data. You can also try to overflow the stack of some thread (for example, recursion) and see what happens (in the sense of a signal). - avp

1 answer 1

Thank you all, the question is closed. Everything turned out to be trivial - SIGSEGV is generated if the thread seizes the lock and terminates its execution without releasing it (it didn’t notice that the mutex forgot to check the validity of the function arguments in one of the branches). All attempts to artificially fill the stack with recursion were unsuccessful - no signals were received from the kernel.