Note that there are some explanatory texts on larger screens.

plurals
  1. POpthread_create memory leak?
    primarykey
    data
    text
    <p>Whenever I run valgrind on my program, it is telling that I have possibly lost memory wherever I call pthread_create. I have been trying to follow the guidance on </p> <p><a href="https://stackoverflow.com/questions/5610677/valgrind-memory-leak-errors-when-using-pthread-create">valgrind memory leak errors when using pthread_create</a> <a href="http://gelorakan.wordpress.com/2007/11/26/pthead_create-valgrind-memory-leak-solved/" rel="nofollow noreferrer">http://gelorakan.wordpress.com/2007/11/26/pthead_create-valgrind-memory-leak-solved/</a></p> <p>and other various websites google gave me, but nothing has worked. So far I have tried joining the threads, setting an pthread_attr_t to DETACHED, calling pthread_detach on each thread, and calling pthread_exit().</p> <p>trying PTHREAD_CREATE_DETACHED - </p> <pre><code>pthread_attr_t attr; pthread_attr_init(&amp;attr); pthread_attr_setdetachstate(&amp;attr, PTHREAD_CREATE_DETACHED); pthread_create(&amp;c_udp_comm, &amp;attr, udp_comm_thread, (void*)this); pthread_create(&amp;drive, &amp;attr, driving_thread, (void*)this); pthread_create(&amp;update, &amp;attr, update_server_thread(void*)this); </code></pre> <p>I think I may have coded this next one with joining wrong...I am going by <a href="https://computing.llnl.gov/tutorials/pthreads/" rel="nofollow noreferrer">https://computing.llnl.gov/tutorials/pthreads/</a> and they have all their threads in an array so they just for loop. But I don't have them all in an array so I tried to just change it to work. Please tell me if I did it wrong.</p> <pre><code>void* status; pthread_attr_t attr; pthread_attr_init(&amp;attr); pthread_attr_setdetachstate(&amp;attr, PTHREAD_CREATE_JOINABLE); pthread_create(&amp;c_udp_comm, &amp;attr, udp_comm_thread, (void*)this); pthread_create(&amp;drive, &amp;attr, driving_thread, (void*)this); pthread_create(&amp;update, &amp;attr, update_server_thread(void*)this); pthread_join(c_udp_comm, &amp;status); pthread_join(drive, &amp;status); pthread_join(update, &amp;status); </code></pre> <p>trying pthread_detach - </p> <pre><code>pthread_create(&amp;c_udp_comm, NULL, udp_comm_thread, (void*)this); pthread_create(&amp;drive, NULL, driving_thread, (void*)this); pthread_create(&amp;update, NULL, update_server_thread(void*)this); pthread_detach(c_udp_comm); pthread_detach(drive); pthread_detach(update); </code></pre> <p>trying pthread_exit - </p> <pre><code>pthread_create(&amp;c_udp_comm, NULL, udp_comm_thread, (void*)this); pthread_create(&amp;drive, NULL, driving_thread, (void*)this); pthread_create(&amp;update, NULL, update_server_thread(void*)this); pthread_exit(NULL); </code></pre> <p>If anyone can help me figure out why none of this is working I would be very grateful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload