问题描述
我有一个使用多处理和多线程的并行编程任务(实施并行解决方案以通过反对角波传播找到两个字符串的LCS)。我有三个单独的数组(实际上是int*
),分别表示“波”的第一个,中间和最后一个对角线,它们都存储在一个结构中,例如:
typedef struct shared_buffer
{
int *back;
int *middle;
int *front;
} shared_buff;
在main()
中,我有以下声明:
// MAX_ANTIDIAG_LENGTH is a macro,defined as the *minimum* of the lengths of the two input strings
int id = shmget(ftok("/dev/null",5),MAX_ANTIDIAG_LENGTH * 3,0644 | IPC_CREAT);
shared_buff* shared_mem = (shared_buff *) shmat(id,nullptr,0);
shared_mem->back = std::memcpy((int*)calloc(MAX_ANTIDIAG_LENGTH,sizeof(int)));
shared_mem->middle = std::memcpy((int*)calloc(MAX_ANTIDIAG_LENGTH,sizeof(int)));
shared_mem->front = std::memcpy((int*)calloc(MAX_ANTIDIAG_LENGTH,sizeof(int)));
但是,据我了解,显然共享内存确实不像存储指针那样,并且在fork()
插入之后就中断了。写入子进程中的数组,并在父进程中打印所述数组, not 不会返回期望值。
因此,我的问题是:如何将这三个数组存储在共享内存中,以便整个进程族可以轻松地用方括号[]
访问所述数组?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)