With some experiments, we found out the method might have some problems if thread which call pypy_init_thread() exited before the later thread call pypy_thread_attach(). Here is the log output: (the thread 6443 call pypy_init_threads() and the thread 6343 later call pypy_thread_attach() ) PypyEnviron inited with thread, id::6343 PypyEnviron inited with thread attach, id::6443 Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007f4b9eba7b82 in rpyvmprof_f_pypy_rrr () from /usr/local/pypy/libpypy-c.so [Current thread is 1 (Thread 0x46557940 (LWP 6443))] (gdb) bt #0 0x00007f4b9eba7b82 in rpyvmprof_f_pypy_rrr () from /usr/local/pypy/libpypy-c.so #1 0x00007f4b9f86897a in rpyvmprof_t_pypy_rrr () from /usr/local/pypy/libpypy-c.so #2 0x00007f4b9eb62ad4 in pypy_g_appexec___src__glob___________________import_sys () from /usr/local/pypy/libpypy-c.so #3 0x00007f4b9eaba80b in pypy_g.pypy_execute_source () from /usr/local/pypy/libpypy-c.so #4 0x00007f4b9eaba994 in pypy_g_pypy_execute_source_ptr () from /usr/local/pypy/libpypy-c.so #5 0x00007f4b9e8a7f42 in pypy_execute_source_ptr () from /usr/local/pypy/libpypy-c.so #6 0x00007f4b9e8a7d82 in pypy_execute_source () from /usr/local/pypy/libpypy-c.so The output of asm looks quite similar as previous. Dump of assembler code for function rpyvmprof_f_pypy_rrr: 0x00007f4b9eba7b40 <+0>: 41 57 push %r15 0x00007f4b9eba7b42 <+2>: 41 56 push %r14 0x00007f4b9eba7b44 <+4>: 41 55 push %r13 0x00007f4b9eba7b46 <+6>: 41 54 push %r12 0x00007f4b9eba7b48 <+8>: 49 89 d5 mov %rdx,%r13 0x00007f4b9eba7b4b <+11>: 55 push %rbp 0x00007f4b9eba7b4c <+12>: 53 push %rbx 0x00007f4b9eba7b4d <+13>: 49 89 f4 mov %rsi,%r12 0x00007f4b9eba7b50 <+16>: 48 89 fb mov %rdi,%rbx 0x00007f4b9eba7b53 <+19>: 48 83 ec 18 sub $0x18,%rsp 0x00007f4b9eba7b57 <+23>: e8 74 ee b6 00 callq 0x7f4b9f7169d0 <pypy_g_stack_check___> 0x00007f4b9eba7b5c <+28>: 48 83 3d 1c 66 94 02 00 cmpq $0x0,0x294661c(%rip) # 0x7f4ba14ee180 <pypy_g_ExcData> 0x00007f4b9eba7b64 <+36>: 0f 85 36 01 00 00 jne 0x7f4b9eba7ca0 <rpyvmprof_f_pypy_rrr+352> 0x00007f4b9eba7b6a <+42>: 66 48 8d 3d 8e b3 2f 01 data16 lea 0x12fb38e(%rip),%rdi # 0x7f4b9fea2f00 0x00007f4b9eba7b72 <+50>: 66 66 48 e8 6e ec cf ff data16 data16 callq 0x7f4b9e8a67e8 <__tls_get_addr@plt> 0x00007f4b9eba7b7a <+58>: f6 43 04 01 testb $0x1,0x4(%rbx) 0x00007f4b9eba7b7e <+62>: 48 8b 68 30 mov 0x30(%rax),%rbp => 0x00007f4b9eba7b82 <+66>: 4c 8b 75 48 mov 0x48(%rbp),%r14 0x00007f4b9eba7b86 <+70>: 0f 85 4c 01 00 00 jne 0x7f4b9eba7cd8 <rpyvmprof_f_pypy_rrr+408> 0x00007f4b9eba7b8c <+76>: f6 45 04 01 testb $0x1,0x4(%rbp) 0x00007f4b9eba7b90 <+80>: 4c 89 73 18 mov %r14,0x18(%rbx) 0x00007f4b9eba7b94 <+84>: 0f 85 2e 01 00 00 jne 0x7f4b9eba7cc8 <rpyvmprof_f_pypy_rrr+392> 0x00007f4b9eba7b9a <+90>: 48 89 5d 48 mov %rbx,0x48(%rbp) 0x00007f4b9eba7b9e <+94>: 48 89 de mov %rbx,%rsi 0x00007f4b9eba7ba1 <+97>: 48 89 ef mov %rbp,%rdi And with "info thread", we confirmed that the thread 6343 was no longer existed: (gdb) info thread Id Target Id Frame 121 Thread 0x4584a940 (LWP 6306) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 120 Thread 0x45648940 (LWP 6302) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 119 Thread 0x43527940 (LWP 6261) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 118 Thread 0x41c32940 (LWP 6219) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 117 Thread 0x43224940 (LWP 6258) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 116 Thread 0x45042940 (LWP 6295) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6 115 Thread 0x45a4c940 (LWP 6309) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 114 Thread 0x41b31940 (LWP 6218) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 113 Thread 0x43628940 (LWP 6262) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 112 Thread 0x42f21940 (LWP 6255) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 111 Thread 0x42416940 (LWP 6244) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 110 Thread 0x40b9a940 (LWP 6227) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 109 Thread 0x44335940 (LWP 6277) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 108 Thread 0x44436940 (LWP 6278) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 107 Thread 0x42618940 (LWP 6246) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 106 Thread 0x44e40940 (LWP 6293) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 105 Thread 0x40a99940 (LWP 6217) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 104 Thread 0x4121f940 (LWP 6243) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 103 Thread 0x402a3940 (LWP 6240) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 102 Thread 0x43729940 (LWP 6263) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 101 Thread 0x42c1e940 (LWP 6252) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 100 Thread 0x42315940 (LWP 6241) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 99 Thread 0x42214940 (LWP 6239) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 98 Thread 0x40992940 (LWP 6229) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 97 Thread 0x44234940 (LWP 6276) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 96 Thread 0x44537940 (LWP 6279) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 95 Thread 0x4281a940 (LWP 6248) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 94 Thread 0x44d3f940 (LWP 6292) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 93 Thread 0x4382a940 (LWP 6266) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 92 Thread 0x4291b940 (LWP 6249) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 91 Thread 0x44638940 (LWP 6280) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 90 Thread 0x4101d940 (LWP 6231) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 89 Thread 0x44133940 (LWP 6275) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 88 Thread 0x44c3e940 (LWP 6291) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 87 Thread 0x47466940 (LWP 6434) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 86 Thread 0x43a2c940 (LWP 6268) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 85 Thread 0x47b6d940 (LWP 6441) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 84 Thread 0x46c5e940 (LWP 6426) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 83 Thread 0x47062940 (LWP 6430) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 82 Thread 0x42a1c940 (LWP 6250) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 81 Thread 0x41d33940 (LWP 6237) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 80 Thread 0x403a4940 (LWP 6283) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 79 Thread 0x42012940 (LWP 6233) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 78 Thread 0x43f31940 (LWP 6273) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 77 Thread 0x47567940 (LWP 6435) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 76 Thread 0x4483a940 (LWP 6287) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 75 Thread 0x43c2e940 (LWP 6270) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 74 Thread 0x46d5f940 (LWP 6427) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 73 Thread 0x4786a940 (LWP 6438) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 72 Thread 0x46b5d940 (LWP 6425) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 71 Thread 0x47264940 (LWP 6432) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 70 Thread 0x46f61940 (LWP 6429) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 69 Thread 0x44739940 (LWP 6284) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 68 Thread 0x43426940 (LWP 6260) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6 67 Thread 0x41e4a940 (LWP 6235) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 66 Thread 0x42b1d940 (LWP 6251) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 ---Type <return> to continue, or q <return> to quit--- 65 Thread 0x47668940 (LWP 6436) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 64 Thread 0x45e50940 (LWP 6313) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 63 Thread 0x46658940 (LWP 6447) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 62 Thread 0x45345940 (LWP 6298) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 61 Thread 0x43d2f940 (LWP 6271) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 60 Thread 0x46e60940 (LWP 6428) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 59 Thread 0x4796b940 (LWP 6439) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 58 Thread 0x46a5c940 (LWP 6423) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 57 Thread 0x47365940 (LWP 6433) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 56 Thread 0x46355940 (LWP 6318) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 55 Thread 0x404a5940 (LWP 6285) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 54 Thread 0x43123940 (LWP 6257) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 53 Thread 0x45547940 (LWP 6300) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 52 Thread 0x47769940 (LWP 6437) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 51 Thread 0x45749940 (LWP 6304) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 50 Thread 0x43e30940 (LWP 6272) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 49 Thread 0x4685a940 (LWP 6421) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 48 Thread 0x416e8940 (LWP 6445) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 47 Thread 0x47a6c940 (LWP 6440) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 46 Thread 0x406b6940 (LWP 6242) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 45 Thread 0x46456940 (LWP 6319) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 44 Thread 0x405a6940 (LWP 6286) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 43 Thread 0x45244940 (LWP 6297) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 42 Thread 0x43022940 (LWP 6256) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 41 Thread 0x44032940 (LWP 6274) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 40 Thread 0x4695b940 (LWP 6422) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 39 Thread 0x42113940 (LWP 6238) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 38 Thread 0x46254940 (LWP 6317) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 37 Thread 0x47163940 (LWP 6431) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 36 Thread 0x45143940 (LWP 6296) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 35 Thread 0x41ecb940 (LWP 6307) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 34 Thread 0x45b4d940 (LWP 6310) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 33 Thread 0x44b3d940 (LWP 6290) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 32 Thread 0x43b2d940 (LWP 6269) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 31 Thread 0x46759940 (LWP 6420) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 30 Thread 0x42719940 (LWP 6247) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 29 Thread 0x41485940 (LWP 6223) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 28 Thread 0x417e9940 (LWP 6234) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 27 Thread 0x46153940 (LWP 6316) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6 26 Thread 0x40f1c940 (LWP 6230) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 25 Thread 0x45f51940 (LWP 6314) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 24 Thread 0x45d4f940 (LWP 6312) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6 23 Thread 0x40d1a940 (LWP 6212) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6 22 Thread 0x44f41940 (LWP 6294) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 21 Thread 0x46052940 (LWP 6315) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 20 Thread 0x45c4e940 (LWP 6311) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 19 Thread 0x4594b940 (LWP 6308) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 18 Thread 0x45446940 (LWP 6299) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 17 Thread 0x4493b940 (LWP 6288) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 16 Thread 0x44a3c940 (LWP 6289) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 15 Thread 0x42e20940 (LWP 6254) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0 14 Thread 0x4392b940 (LWP 6267) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 13 Thread 0x43325940 (LWP 6259) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 12 Thread 0x42517940 (LWP 6245) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 11 Thread 0x42d1f940 (LWP 6253) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 10 Thread 0x418ea940 (LWP 6236) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 9 Thread 0x41384940 (LWP 6213) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 ---Type <return> to continue, or q <return> to quit--- 8 Thread 0x4111e940 (LWP 6232) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 7 Thread 0x41586940 (LWP 6224) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 6 Thread 0x40854940 (LWP 6222) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 5 Thread 0x4014e940 (LWP 6228) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6 4 Thread 0x7f4ba9c048b0 (LWP 6056) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6 3 Thread 0x41a30940 (LWP 6446) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 2 Thread 0x40e1b940 (LWP 6444) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 * 1 Thread 0x46557940 (LWP 6443) 0x00007f4b9eba7b82 in rpyvmprof_f_pypy_rrr () from /usr/local/pypy/libpypy-c.so