~nabijaczleweli/ossp#191: 
[mm 1.4.2] two process don't map the same address with same parameter of file

#Upstream Ticket 191 from 2012-10-24 08:31:35

I have two process, write and read. The two process build the shared memory with mm_create, and parameter of file point the same file. but the return point MM point the different address.

Status
REPORTED
Submitter
~nabijaczleweli
Assigned to
No-one
Submitted
4 months ago
Updated
4 months ago
Labels
CVSTrac mm

~nabijaczleweli 4 months ago

#Attached read.c on 2012-10-24 08:32:57

//gcc write.c -o  write -g
#include <stdio.h>
#include <string.h>

#include "/usr/local/include/mm.h"

struct shm{
	int a;
	char b;
	float c;
}*pt;

int main()
{
	size_t size_mem;
	MM *p_mm;
	size_mem = 1024;
	int a;
	char b;
	float c;

	p_mm = mm_create(size_mem,"../mm");
	if(p_mm == NULL)
	{
	    perror("error");
	    return 0;
	}
	pt = (struct shm*)p_mm;
	printf("addr_p_mm =%x\n",p_mm);
	printf("addr_pt =%x\n",pt);
	while(1)
	{
	    mm_lock(p_mm,MM_LOCK_RW);
	    a = pt->a;
	    b = pt->b;
	    c = pt->c;
	    mm_unlock(p_mm);
	    printf("a = %d,b = %d,c = %f \n",a,b,c);
	    sleep(5);
	}
	return 0;
}

~nabijaczleweli 4 months ago

#Attached write.c on 2012-10-24 08:33:12

//gcc write.c -o  write -g
#include <stdio.h>
#include <string.h>

#include "mm.h"

struct shm{
	int a;
	char b;
	float c;
}*pt;

int main()
{
	size_t size_mem;
	MM* p_mm;
	size_mem = 1024;
	p_mm = mm_create(size_mem,"../mm");
	if(p_mm == NULL)
	{
	    perror("error");
	    return 0;
	}
	mm_reset(p_mm);
	pt = (struct shm*)p_mm;
	printf("addr_p_mm =%x\n",p_mm);
	printf("addr_pt =%x\n",pt);
	while(1)
	{
	    mm_lock(p_mm,MM_LOCK_RW);		 
	    pt->a = 1;
	    pt->b = 2;
	    pt->c = 3;
	    mm_unlock(p_mm);	
	    sleep(4);	
	}
	mm_destroy(p_mm);
	return 0;
}

~nabijaczleweli 4 months ago

#Attached makefile on 2012-10-24 08:33:27

CC=cc
CFLAGS=-O '-I/usr/local/include'
LDFLAGS='-L/usr/local/lib'
LIBS=-lm '-lmm'

all: read
read: read.o
	$(CC) $(LDFLAGS) -o read read.o $(LIBS)
read.o: read.c
	$(CC) $(CFLAGS) -c read.c

Register here or Log in to comment, or comment via email.