SIGSEGV in 'free' function of libpthread, but backtrace does not list any of my files/funcs

0

I have an OpenCL program that uses only one device (GPU in this case) and I am using 3 pthreads to manage the program (plus the main thread).

Sometimes I get a SIGSEGV, but I have no clue why it happens.

Thread 13 "my_program" received signal SIGSEGV, Segmentation fault.

[Thread 0x7fffc5aef700 (LWP 20058) exited]
[Thread 0x7fffc62f0700 (LWP 20057) exited]
[Thread 0x7fffc6af1700 (LWP 20056) exited]

Thread 13 "my_program" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffa22ee700 (LWP 20181)]
─── Assembly ─────────────────────────────────────────────────────────────────────────────────────────────
0x00007ffff6d7bfc2 free+-17256558 jne    0x7ffff6d7c070 <free+192>
0x00007ffff6d7bfc8 free+-17256552 test   %rdi,%rdi
0x00007ffff6d7bfcb free+-17256549 je     0x7ffff6d7c060 <free+176>
0x00007ffff6d7bfd1 free+-17256543 mov    -0x8(%rdi),%rax
0x00007ffff6d7bfd5 free+-17256539 lea    -0x10(%rdi),%rsi
0x00007ffff6d7bfd9 free+-17256535 test   $0x2,%al
0x00007ffff6d7bfdb free+-17256533 jne    0x7ffff6d7c018 <free+104>
─── Expressions ──────────────────────────────────────────────────────────────────────────────────────────
─── History ──────────────────────────────────────────────────────────────────────────────────────────────
─── Memory ───────────────────────────────────────────────────────────────────────────────────────────────
─── Registers ────────────────────────────────────────────────────────────────────────────────────────────
   rax 0x0000000000000000    rbx 0x0000000000000001    rcx 0x00007fffc6af19c0    rdx 0x00007fffc62f09c0
   rsi 0x0000000000000000    rdi 0x0005a9390005a938    rbp 0x0000000000622570    rsp 0x00007fffa22ede80
    r8 0x00007fff880008c0     r9 0x00000000ffffffff    r10 0x0000000000000000    r11 0x0000000000000206
   r12 0x00007fffc5aef700    r13 0x0000000000000000    r14 0x00007fffa22ee700    r15 0x0000000000000000
   rip 0x00007ffff6d7bfd1 eflags [ IF RF ]              cs 0x00000033             ss 0x0000002b
    ds 0x00000000             es 0x00000000             fs 0x00000000             gs 0x00000000
─── Source ───────────────────────────────────────────────────────────────────────────────────────────────
─── Stack ────────────────────────────────────────────────────────────────────────────────────────────────
[0] from 0x00007ffff6d7bfd1 in free+-17256543
(no arguments)
[1] from 0x00007ffff7dea5d6 in _dl_deallocate_tls+54
(no arguments)
[+]
─── Threads ──────────────────────────────────────────────────────────────────────────────────────────────
[20] id 20197 name my_program from 0x00007ffff79aacc6 in do_futex_wait.constprop
[19] id 20196 name my_program from 0x00007ffff79aacc6 in do_futex_wait.constprop
[18] id 20194 name my_program from 0x00007ffff79ab6db in __lll_lock_wait_private+12251451
[17] id 20188 name my_program from 0x00007ffff79ab6db in __lll_lock_wait_private+12251451
[16] id 20184 name my_program from 0x00007ffff79ab6db in __lll_lock_wait_private+12251451
[15] id 20183 name my_program from 0x00007ffff79ab6db in __lll_lock_wait_private+12251451
[14] id 20182 name my_program from 0x00007ffff79ab6db in __lll_lock_wait_private+12251451
[13] id 20181 name my_program from 0x00007ffff6d7bfd1 in free+-17256543
[12] id 20172 name my_program from 0x00007ffff6dd7177 in sched_yield+7
[11] id 20066 name si_shader_low:1 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[10] id 20065 name si_shader_low:0 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[9] id 20064 name si_shader:2 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[8] id 20063 name si_shader:1 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[7] id 20062 name si_shader:0 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[6] id 20061 name disk_cache:0 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[5] id 20059 name amdgpu_cs:0 from 0x00007ffff79a838d in pthread_cond_wait@@GLIBC_2.3.2
[1] id 19816 name my_program from 0x00007ffff6dd7177 in sched_yield+7
──────────────────────────────────────────────────────────────────────────────────────────────────────────
0x00007ffff6d7bfd1 in free () from /usr/lib/libc.so.6
>>> bt
#0  0x00007ffff6d7bfd1 in free () from /usr/lib/libc.so.6
#1  0x00007ffff7dea5d6 in _dl_deallocate_tls () from /lib64/ld-linux-x86-64.so.2
#2  0x00007ffff79a1307 in __free_stacks () from /usr/lib/libpthread.so.0
#3  0x00007ffff79a145a in __deallocate_stack () from /usr/lib/libpthread.so.0
#4  0x00007ffff79a2354 in start_thread () from /usr/lib/libpthread.so.0
#5  0x00007ffff6def47f in clone () from /usr/lib/libc.so.6

As you can see when I am doing backtrace I only get functions outside my program.

This is how I create and destroy one of these 3 pthreads.

int main(){
  //...
  pthread_t pthreadRead;
  pthread_attr_t attrRead;
  pthread_cond_init(&pcondRead, NULL);
  pthread_attr_init(&attrRead);
  pthread_attr_setdetachstate(&attrRead, PTHREAD_CREATE_DETACHED);
  pthread_create(&pthreadRead, &attrRead, pthreadRead_func, NULL);

  //...
  // waits for completion (OpenCL)
  //...

  pthread_attr_destroy(&attrRead);
  //...
}

The main function of a thread:

void* pthreadRead_func(void* ptr) {

  bool cont = true;
  while (cont) {
    pthread_mutex_lock(&pmutexRead);
    while (!signaledRead) {
      pthread_cond_wait(&pcondRead, &pmutexRead);
    }

    // doing OpenCL calls and operations
    if (conditionMeet){
      cont = false;
    }

    signaledRead = 0;
    pthread_mutex_unlock(&pmutexRead);
  }

  pthread_exit(0);
  return (void*)0;
}

How can I understand what is going on if I cannot track the error to my code?

#0  0x00007ffff6d7bfd1 in free () from /usr/lib/libc.so.6
#1  0x00007ffff7dea5d6 in _dl_deallocate_tls () from /lib64/ld-linux-x86-64.so.2
#2  0x00007ffff79a1307 in __free_stacks () from /usr/lib/libpthread.so.0
#3  0x00007ffff79a145a in __deallocate_stack () from /usr/lib/libpthread.so.0
#4  0x00007ffff79a2354 in start_thread () from /usr/lib/libpthread.so.0
#5  0x00007ffff6def47f in clone () from /usr/lib/libc.so.6
c++
multithreading
pthreads
opencl
asked on Stack Overflow Nov 27, 2017 by user3819881 • edited Nov 27, 2017 by e2-e4

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0