Thank you , Chris . Now I am facing a trouble of how to protect a dynamically allocated memory . The description is this :
Process of function 1 :
1, Using calloc () function to generate a sequential space in the memory , filling in the space with a struct type data .
2, Return head address of the allocated space .
In function 2 :
1, Define a global struct pointer type variable , which point to the returned value from function 1.
2 , spawn 2 threads , one used to write data to the preallocated memory , and the other used to read out data from it .
In such an application , actually , the allocated space can be accessed by an array of struct pointer ,so if define such a global : struct myData * mData ; you can use subscript of the pointer to access t
he space , e.g., mData [0] = the first data of the space .
Having to protect the dynamically allocated memory , so I want to use the method of thread safe variable , that is , using array as safe variable . but before stating the macro of DefineThreadSafeArrayVar (struct myData, mData, number, 0), the array size must be known in advance , due to the space is allocated dynamically , it is sure that can not know the array size before stating the macro . So , is there any way to resolve the problem ?
Please do not consider TSQ method , since the actually situation do not let me to create such a mechanism . Your advise is highly appreciated .
David