I am making a multi-threaded C program which involves the sharing of a global dynamic integer array between two threads. One thread will keep adding elements to it & the other will independently scan the array & free the scanned elements. I will use realloc to increment the array & use a local int pointer in the other thread to keep track of the elements scanned. However, my problem is how to free the elements after they have been scanned by my 2nd thread. I tried by having a pointer point to each element of the global array in a for loop & then using the free function, but it only cleared the 1st element. Can somebody please suggest a way out.
On a side note, is this the right way to handle this problem?