I am running some code which will start two threads. Both the threads will be working on same list of nodes. First thread will be dynamically inserting and deleting. Second thread will deleting basing on certain parameters I will be providing.
As there are chances to delete the same node twice(once by each thread), I adopted the following procedure:
- obtain the lock
- ensure that the node(memory) is still existing which is being pointed by the present thread
- delete the node.
- release the lock
here the complication is in the second line. I thought sizeof operator will be help me. But It is not helping me. I tried the following code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *ptr=NULL;
printf("\nsize one : %d",sizeof(ptr));
printf("\nbefore allocation ptr: %u",ptr);
ptr=(char*)malloc(10);
printf("\nafter allocation ptr: %u",ptr);
printf("\nsize two : %d",sizeof(ptr));
free(ptr);
printf("\nafter freeing mem. ptr: %u",ptr);
printf("\nsize three : %d\n\n",sizeof(ptr));
return(0);
}
output is as follows:
Quote:
size one : 4
before allocation ptr: 0
after allocation ptr: 153280520
size two : 4
after freeing mem. ptr: 153280520
size three : 4
|
I want the following output:
Quote:
size one : 0
before allocation ptr: 0
after allocation ptr: 153280520
size two : 10
after freeing mem. ptr: 153280520
size three : 0
|
Can any body please help me by giving the relevent function call which will serve my purpose.