read.c
1 
30 #include <unistd.h> /* for usleep() */
31 #include <shm_arena.h> /* for Shared Memory Arena Library */
32 
33 
34 int main(void)
35 {
36  int *ptr;
37  int running = 1;
38 
39  ptr = (int *) sm_get(sizeof(int), "count");
40  if(!ptr)
41  {
42  printf("sm_get() failed\n");
43  return 1;
44  }
45 
46  while(running)
47  {
48  usleep(600000); /* micro seconds */
49 
50  sm_rdlock(ptr);
51 
52  printf("read %d\n", *ptr);
53  if(*ptr >= 10) running = 0;
54 
55  sm_unlock(ptr);
56  }
57 
58  return 0;
59 }
static int sm_unlock(const void *ptr)
release a shared memory segment read-write lock
Definition: shm_arena.h:548
static void * sm_get(size_t size, const char *name)
get a shared memory segment
Definition: shm_arena.h:329
static int sm_rdlock(const void *ptr)
acquire a shared memory segment read lock
Definition: shm_arena.h:524

Shared Memory Arena version RC-0.0.25