File: demo.c

package info (click to toggle)
rtlinux 3.1pre3-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 4,896 kB
  • ctags: 4,228
  • sloc: ansic: 26,204; sh: 2,069; makefile: 1,414; perl: 855; tcl: 489; asm: 380; cpp: 42
file content (24 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>

#include "mbuff.h"

/* the contents of shared memory may change at any time, thus volatile */
volatile char * shm1, *shm2;

main (int argc,char *argv[]){
   
	shm1 = (volatile char*) mbuff_alloc("demo1",1024*1024);
	shm2 = (volatile char*) mbuff_alloc("demo1",1024*1024);
	if( shm1 == NULL || shm2 == NULL ) {
		printf("mbuff_alloc failed\n");
		exit(2);
	}
	sprintf((char*)shm1,"example data\n");
	sleep(5); /* you may change it from the kernel or other program here */
	printf("shm1=%p shm2=%p shm2->%s", shm1, shm2, shm2);
	mbuff_free("demo1",(void*)shm1);
	sleep(3);
	/* you may still access shm2 here, it is still the same memory area */
	mbuff_free("demo1",(void*)shm2);
	return(0);
}