how to set pointer to a memory to NULL using memset?

后端 未结 9 880
执笔经年
执笔经年 2020-12-11 08:35

I have a structure

typedef struct my_s {

   int x;
   ...
} my_T;

my_t * p_my_t;

I want to set the address of p_my_t to

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 09:31

    Per your update, it seems to me that what you are really trying to do is guard access to a resource, which means you should use a read/write lock that is shared between the processes to guard the ptr to that resource, and test the ptr before using.

    • Allocate the structure in shared memory.
    • Allocate the ptr to the structure in shared memory.
    • Guard access to the ptr to the structure with a Read/Write lock.
    • Process A should acquire a WRITE lock to the ptr when initializing or invalidating the ptr and structure.
    • Process B should acquire a READ lock to the ptr, and test that the ptr is valid before using the structure

提交回复
热议问题