简体   繁体   中英

How to prevent memory leaks in pthreads?

How to prevent memory leaks in pthread? I am running a server client program where server has to execute a pthread program and pss the result to client. The client keeps asking for the command again and again until it is stopped. The result provided by server is true only in the first iteration but it is providing incorrect results from second iteration.

I tried to use pthread_join and pthread_exit to prevent memory leaks but still its showing incorrect results.

When you have concurrent threads, these are working in the same address room which means that they'll share their memory. So modifying the variable in the first thread will alter the variables in the next thread.

You probably initialized the variables correctly in the beginning which leads to correct results. But after your first run, these aren't initialized correctly anymore.

Start debugging by checking the initial conditions and comparing these between the first and the second run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM