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::6343PypyEnviron inited with thread attach, id::6443Program 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.soThe output of asm looks quite similar as previous.Dump of assembler code for function rpyvmprof_f_pypy_rrr:0x00007f4b9eba7b40 <+0>: 41 57 push %r150x00007f4b9eba7b42 <+2>: 41 56 push %r140x00007f4b9eba7b44 <+4>: 41 55 push %r130x00007f4b9eba7b46 <+6>: 41 54 push %r120x00007f4b9eba7b48 <+8>: 49 89 d5 mov %rdx,%r130x00007f4b9eba7b4b <+11>: 55 push %rbp0x00007f4b9eba7b4c <+12>: 53 push %rbx0x00007f4b9eba7b4d <+13>: 49 89 f4 mov %rsi,%r120x00007f4b9eba7b50 <+16>: 48 89 fb mov %rdi,%rbx0x00007f4b9eba7b53 <+19>: 48 83 ec 18 sub $0x18,%rsp0x00007f4b9eba7b57 <+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 # 0x7f4b9fea2f000x00007f4b9eba7b72 <+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),%r140x00007f4b9eba7b86 <+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,%rsi0x00007f4b9eba7ba1 <+97>: 48 89 ef mov %rbp,%rdiAnd with "info thread", we confirmed that the thread 6343 was no longer existed:(gdb) info threadId Target Id Frame121 Thread 0x4584a940 (LWP 6306) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0120 Thread 0x45648940 (LWP 6302) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0119 Thread 0x43527940 (LWP 6261) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0118 Thread 0x41c32940 (LWP 6219) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0117 Thread 0x43224940 (LWP 6258) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0116 Thread 0x45042940 (LWP 6295) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.6115 Thread 0x45a4c940 (LWP 6309) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0114 Thread 0x41b31940 (LWP 6218) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0113 Thread 0x43628940 (LWP 6262) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0112 Thread 0x42f21940 (LWP 6255) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0111 Thread 0x42416940 (LWP 6244) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6110 Thread 0x40b9a940 (LWP 6227) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6109 Thread 0x44335940 (LWP 6277) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6108 Thread 0x44436940 (LWP 6278) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.0107 Thread 0x42618940 (LWP 6246) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6106 Thread 0x44e40940 (LWP 6293) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0105 Thread 0x40a99940 (LWP 6217) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0104 Thread 0x4121f940 (LWP 6243) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6103 Thread 0x402a3940 (LWP 6240) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6102 Thread 0x43729940 (LWP 6263) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0101 Thread 0x42c1e940 (LWP 6252) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.6100 Thread 0x42315940 (LWP 6241) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.699 Thread 0x42214940 (LWP 6239) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.698 Thread 0x40992940 (LWP 6229) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.697 Thread 0x44234940 (LWP 6276) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.096 Thread 0x44537940 (LWP 6279) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.095 Thread 0x4281a940 (LWP 6248) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.694 Thread 0x44d3f940 (LWP 6292) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.693 Thread 0x4382a940 (LWP 6266) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.692 Thread 0x4291b940 (LWP 6249) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.691 Thread 0x44638940 (LWP 6280) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.090 Thread 0x4101d940 (LWP 6231) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.689 Thread 0x44133940 (LWP 6275) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.088 Thread 0x44c3e940 (LWP 6291) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.687 Thread 0x47466940 (LWP 6434) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.086 Thread 0x43a2c940 (LWP 6268) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.085 Thread 0x47b6d940 (LWP 6441) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.084 Thread 0x46c5e940 (LWP 6426) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.083 Thread 0x47062940 (LWP 6430) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.082 Thread 0x42a1c940 (LWP 6250) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.681 Thread 0x41d33940 (LWP 6237) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.680 Thread 0x403a4940 (LWP 6283) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.679 Thread 0x42012940 (LWP 6233) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.678 Thread 0x43f31940 (LWP 6273) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.077 Thread 0x47567940 (LWP 6435) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.076 Thread 0x4483a940 (LWP 6287) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.675 Thread 0x43c2e940 (LWP 6270) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.074 Thread 0x46d5f940 (LWP 6427) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.073 Thread 0x4786a940 (LWP 6438) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.072 Thread 0x46b5d940 (LWP 6425) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.071 Thread 0x47264940 (LWP 6432) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.070 Thread 0x46f61940 (LWP 6429) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.069 Thread 0x44739940 (LWP 6284) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.668 Thread 0x43426940 (LWP 6260) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.667 Thread 0x41e4a940 (LWP 6235) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.666 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.064 Thread 0x45e50940 (LWP 6313) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.063 Thread 0x46658940 (LWP 6447) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.062 Thread 0x45345940 (LWP 6298) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.061 Thread 0x43d2f940 (LWP 6271) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.060 Thread 0x46e60940 (LWP 6428) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.059 Thread 0x4796b940 (LWP 6439) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.058 Thread 0x46a5c940 (LWP 6423) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.057 Thread 0x47365940 (LWP 6433) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.056 Thread 0x46355940 (LWP 6318) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.055 Thread 0x404a5940 (LWP 6285) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.654 Thread 0x43123940 (LWP 6257) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.053 Thread 0x45547940 (LWP 6300) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.052 Thread 0x47769940 (LWP 6437) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.051 Thread 0x45749940 (LWP 6304) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.050 Thread 0x43e30940 (LWP 6272) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.049 Thread 0x4685a940 (LWP 6421) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.048 Thread 0x416e8940 (LWP 6445) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.047 Thread 0x47a6c940 (LWP 6440) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.046 Thread 0x406b6940 (LWP 6242) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.645 Thread 0x46456940 (LWP 6319) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.044 Thread 0x405a6940 (LWP 6286) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.643 Thread 0x45244940 (LWP 6297) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.042 Thread 0x43022940 (LWP 6256) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.041 Thread 0x44032940 (LWP 6274) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.040 Thread 0x4695b940 (LWP 6422) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.039 Thread 0x42113940 (LWP 6238) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.638 Thread 0x46254940 (LWP 6317) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.037 Thread 0x47163940 (LWP 6431) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.036 Thread 0x45143940 (LWP 6296) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.035 Thread 0x41ecb940 (LWP 6307) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.634 Thread 0x45b4d940 (LWP 6310) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.033 Thread 0x44b3d940 (LWP 6290) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.632 Thread 0x43b2d940 (LWP 6269) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.031 Thread 0x46759940 (LWP 6420) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.030 Thread 0x42719940 (LWP 6247) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.629 Thread 0x41485940 (LWP 6223) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.628 Thread 0x417e9940 (LWP 6234) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.627 Thread 0x46153940 (LWP 6316) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.626 Thread 0x40f1c940 (LWP 6230) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.625 Thread 0x45f51940 (LWP 6314) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.024 Thread 0x45d4f940 (LWP 6312) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.623 Thread 0x40d1a940 (LWP 6212) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.622 Thread 0x44f41940 (LWP 6294) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.021 Thread 0x46052940 (LWP 6315) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.020 Thread 0x45c4e940 (LWP 6311) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.019 Thread 0x4594b940 (LWP 6308) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.018 Thread 0x45446940 (LWP 6299) 0x00007f4ba3c5bf59 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.017 Thread 0x4493b940 (LWP 6288) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.616 Thread 0x44a3c940 (LWP 6289) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.615 Thread 0x42e20940 (LWP 6254) 0x00007f4ba3c5dd91 in sem_wait () from /lib64/libpthread.so.014 Thread 0x4392b940 (LWP 6267) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.613 Thread 0x43325940 (LWP 6259) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.612 Thread 0x42517940 (LWP 6245) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.611 Thread 0x42d1f940 (LWP 6253) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.010 Thread 0x418ea940 (LWP 6236) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.69 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.67 Thread 0x41586940 (LWP 6224) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.66 Thread 0x40854940 (LWP 6222) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.65 Thread 0x4014e940 (LWP 6228) 0x00007f4ba1f8fd98 in epoll_wait () from /lib64/libc.so.64 Thread 0x7f4ba9c048b0 (LWP 6056) 0x00007f4ba1f55901 in nanosleep () from /lib64/libc.so.63 Thread 0x41a30940 (LWP 6446) 0x00007f4ba3c5c1c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.02 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