How to prevent memory leaks in pthreads?

64 views Asked by At

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.

1

There are 1 answers

1
0x7477 On

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