I wrote a small pthread multithreadding programming and i wanted to clean up the pthred_t array which i created. But when I do it I get the error that a glib has been detected. How can I delete the array, or do I simply not need to. The code runs fine without the freeing of the memory but in my opinion the code below causes a (small) memory leek.
Thanks
pthread_t* threadNumber = new pthread_t (4);
args var;
var.matrixA=matrixA;
var.matrixB=matrixB;
var.matrixC=matrixC;
var.alpha=alpha;
var.beta=beta;
var.cellCount=0;
var.maxCells=cColumns*cRows;
for (int i =0 ;i<4;++i)
pthread_create(&threadNumber[i],&attr,matrixMultiply,(void *) (&var));
for(int i=0;i<4;++i)
pthread_join(threadNumber[i],NULL);
printMatrix(matrixA,aRows,aColumns);
printMatrix(matrixB,bRows,bColumns);
printMatrix(matrixC,cRows,cColumns);
//delete threadNumber;
//this caused a memory trash
You need square bracket to create array:
Not this:
But this is correct:
Your version is one pthread_t variable initialized to
4– whatever this4means in this context – since pthread_t is opaque type.So, with your wrong version you should delete with
delete threadNumber, correct version delete withdelete [] threadNumber