+ -
当前位置:首页 → 问答吧 → 两个行程open同一个memory device且都mmap到logical address来作读写,会产生问题吗?

两个行程open同一个memory device且都mmap到logical address来作读写,会产生问题吗?

时间:2010-03-01

来源:互联网

如题~
我有两个行程A和B,各自都会产生一个while(1) thread,而thread都会open同一个
memory device且mmap到logical address来作读写,以下为我的程式码的"示意"写法:

int process_A()
{
pthread_create(thread_A);

pthread_join(); //wait thread_A terminate

}

void thraed_A()
{
int fd;
unsigned int *addr;

fd = open("/dev/mem_dev", O_RDWR);
addr = mmap(0, 0x1000000, PROT_WRITE, MAP_SHARED, fd, 0)

while(1)
{
if(Condition == TRUE)
{
read/write on addr;
}

}
}

int process_B()
{
pthread_create(thread_B);

pthread_join(); //wait thread_B terminate

}

void thraed_B()
{
int fd;
unsigned int *addr;

fd = open("/dev/mem_dev", O_RDWR);
addr = mmap(0, 0x1000000, PROT_WRITE, MAP_SHARED, fd, 0)

while(1)
{
if(Condition == TRUE)
{
read/write on addr;
}

}
}

两个行程open同一个memory device且都mmap到logical address来作读写,会产生不可预知的问题吗?

在我的测试中,其中一个process好像都会被莫名的kill掉,甚至还会出现page fault?
但若关掉其中一个,另一个都能*正常*执行!!!

请问各位大大,若两个while(1)行程都到open同一个memory device且mmap到logical address作读写,
有地方需要注意的嘛?还是根本不行同时open同一个memory device且mmap到logical address作读写???


谢谢!!!

作者: hillvskobe   发布时间: 2010-03-01

没同步?

作者: ashindenise   发布时间: 2010-04-15

不是资料不同步的问题,是其中一个行程会被莫名杀掉???

作者: hillvskobe   发布时间: 2010-04-15