<small id='ChKTg'></small><noframes id='ChKTg'>

      <bdo id='ChKTg'></bdo><ul id='ChKTg'></ul>

    1. <i id='ChKTg'><tr id='ChKTg'><dt id='ChKTg'><q id='ChKTg'><span id='ChKTg'><b id='ChKTg'><form id='ChKTg'><ins id='ChKTg'></ins><ul id='ChKTg'></ul><sub id='ChKTg'></sub></form><legend id='ChKTg'></legend><bdo id='ChKTg'><pre id='ChKTg'><center id='ChKTg'></center></pre></bdo></b><th id='ChKTg'></th></span></q></dt></tr></i><div id='ChKTg'><tfoot id='ChKTg'></tfoot><dl id='ChKTg'><fieldset id='ChKTg'></fieldset></dl></div>
      <legend id='ChKTg'><style id='ChKTg'><dir id='ChKTg'><q id='ChKTg'></q></dir></style></legend>
      <tfoot id='ChKTg'></tfoot>
    2. 使用 pthread_create 时的 valgrind 内存泄漏错误

      时间:2023-09-26

      1. <legend id='c09Vq'><style id='c09Vq'><dir id='c09Vq'><q id='c09Vq'></q></dir></style></legend>

        <tfoot id='c09Vq'></tfoot>
        <i id='c09Vq'><tr id='c09Vq'><dt id='c09Vq'><q id='c09Vq'><span id='c09Vq'><b id='c09Vq'><form id='c09Vq'><ins id='c09Vq'></ins><ul id='c09Vq'></ul><sub id='c09Vq'></sub></form><legend id='c09Vq'></legend><bdo id='c09Vq'><pre id='c09Vq'><center id='c09Vq'></center></pre></bdo></b><th id='c09Vq'></th></span></q></dt></tr></i><div id='c09Vq'><tfoot id='c09Vq'></tfoot><dl id='c09Vq'><fieldset id='c09Vq'></fieldset></dl></div>
          <tbody id='c09Vq'></tbody>
      2. <small id='c09Vq'></small><noframes id='c09Vq'>

              <bdo id='c09Vq'></bdo><ul id='c09Vq'></ul>

              • 本文介绍了使用 pthread_create 时的 valgrind 内存泄漏错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 pthread 库编写程序.当我使用命令 valgrind --leak-check=full 运行我的程序时,我得到以下错误描述:

                I'm writing a program using the pthread library. When I run my program with the command valgrind --leak-check=full, I get the following errors description:

                ==11784==  
                ==11784== **HEAP SUMMARY:**  
                ==11784==     in use at exit: 4,952 bytes in 18 blocks  
                ==11784==   total heap usage: 1,059 allocs, 1,041 frees, 51,864 bytes allocated  
                ==11784==  
                ==11784== **288 bytes** in 1 blocks are possibly lost in loss record 2 of 3  
                ==11784==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)  
                ==11784==    by 0x4010D2E: _dl_allocate_tls (dl-tls.c:300)  
                ==11784==    by 0x55DC218: **pthread_create**@@GLIBC_2.2.5 (allocatestack.c:570)  
                ==11784==    by 0x401BC0: initdevice(char*) (in /a/fr-01/vol/home/stud/lim/workspace  /Ex3/l)  
                ==11784==    by 0x406D05: main (in /a/fr-01/vol/home/stud/lim/workspace/Ex3/l)  
                ==11784==  
                ==11784== **4,608 bytes** in 16 blocks are possibly lost in loss record 3 of 3  
                ==11784==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)  
                ==11784==    by 0x4010D2E: _dl_allocate_tls (dl-tls.c:300)  
                ==11784==    by 0x55DC218: **pthread_create**@@GLIBC_2.2.5 (allocatestack.c:570)    
                ==11784==    by 0x40268F: write2device(char*, int) (in /a/fr-01/vol/home/stud/lim/workspace/Ex3/l)  
                ==11784==    by 0x406D7B: main (in /a/fr-01/vol/home/stud/lim/workspace/Ex3/l)  
                ==11784==  
                ==11784== **LEAK SUMMARY:**  
                ==11784==    definitely lost: 0 bytes in 0 blocks  
                ==11784==    indirectly lost: 0 bytes in 0 blocks  
                ==11784==      possibly lost: 4,896 bytes in 17 blocks  
                ==11784==    still reachable: 56 bytes in 1 blocks  
                ==11784==         suppressed: 0 bytes in 0 blocks  
                ==11784== Reachable blocks (those to which a pointer was found) are not shown.  
                ==11784== To see them, rerun with: --leak-check=full --show-reachable=yes  
                ==11784==  
                ==11784== For counts of detected and suppressed errors, rerun with: -v  
                ==11784== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 4 from 4)  
                

                <小时>

                每次我调用pthread_create 时,都会使用某个函数——我在函数末尾调用函数pthread_exit.那么,在确认这不是问题后,可能是什么问题?


                Every time I call pthread_create, with a certain function - I call the function pthread_exit in the end of the function. So, after verifying this is not the problem, what could be the problem?

                推荐答案

                线程的资源不会在终止时立即释放,除非创建线程时 detach state 属性设置为PTHREAD_CREATE_DETACHED,或者如果 pthread_detach 被调用它的pthread_t.

                A thread's resources are not immediately released at termination, unless the thread was created with the detach state attribute set to PTHREAD_CREATE_DETACHED, or if pthread_detach is called for its pthread_t.

                未分离的线程将保持终止状态,直到将其标识符传递给 pthread_joinpthread_detach.

                An undetached thread will remain terminated state until its identifier is passed to pthread_join or pthread_detach.

                总结起来,你有三个选择:

                To sum it up, you have three options:

                1. 使用分离属性集(PTHREAD_CREATE_DETACHED 属性)创建您的线程
                2. 创建后分离线程(通过调用pthread_detach),或
                3. 加入终止的线程以回收它们(通过调用pthread_join).

                这篇关于使用 pthread_create 时的 valgrind 内存泄漏错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何正确取消初始化 OpenSSL 下一篇:没有 delete() 的 new() 是未定义行为还是仅仅是内存泄漏?

                相关文章

                    • <bdo id='mtptw'></bdo><ul id='mtptw'></ul>

                    <small id='mtptw'></small><noframes id='mtptw'>

                  1. <tfoot id='mtptw'></tfoot>

                    <legend id='mtptw'><style id='mtptw'><dir id='mtptw'><q id='mtptw'></q></dir></style></legend>
                  2. <i id='mtptw'><tr id='mtptw'><dt id='mtptw'><q id='mtptw'><span id='mtptw'><b id='mtptw'><form id='mtptw'><ins id='mtptw'></ins><ul id='mtptw'></ul><sub id='mtptw'></sub></form><legend id='mtptw'></legend><bdo id='mtptw'><pre id='mtptw'><center id='mtptw'></center></pre></bdo></b><th id='mtptw'></th></span></q></dt></tr></i><div id='mtptw'><tfoot id='mtptw'></tfoot><dl id='mtptw'><fieldset id='mtptw'></fieldset></dl></div>