if((shmptr=shmat(shm_id,0,0))==(void *)-1)出现invalid conversion from 'void*'to'container_buffer*'
voidv(intsem_id,intsem_num){structsembufsem_buff;sem_buff.sem_num=sem_num;sem_buff.se...
void v(int sem_id, int sem_num)
{
struct sembuf sem_buff;
sem_buff.sem_num = sem_num;
sem_buff.sem_op = 1;
sem_buff.sem_flg = 0;
semop(sem_id, &sem_buff, 1);
}
int main(int argc, char * argv[])
{
int shm_id, sem_id;
int num_p = 0, num_c = 0, i, j;
struct container_buffer * shmptr;
char pn;
time_t now;
pid_t pid_p, pid_c;
printf("Main process starts.\n");
sem_id = semget(SEM_ALL_KEY, 2, IPC_CREAT | 0660);
semctl(sem_id, SEM_EMPTY, SETVAL, BUFFER_NUM);
semctl(sem_id, SEM_FULL, SETVAL, 0);
if ((shm_id = shmget(IPC_PRIVATE, BUF_LENGTH, SHM_MODE)) < 0)
{
exit(1);
}
if ((shmptr = shmat(shm_id, 0, 0)) == (void *)-1)
{
exit(1);
}
shmptr->head = 0;
shmptr->tail = 0;
shmptr->is_empty = 1;
while ((num_p++) < PRODUCER)
{
if ((pid_p = fork()) < 0)
{
exit(1);
}
if (pid_p == 0)
{
if ((shmptr = shmat(shm_id, 0, 0)) == (void *)-1)
{
exit(1);
}
下略 展开
{
struct sembuf sem_buff;
sem_buff.sem_num = sem_num;
sem_buff.sem_op = 1;
sem_buff.sem_flg = 0;
semop(sem_id, &sem_buff, 1);
}
int main(int argc, char * argv[])
{
int shm_id, sem_id;
int num_p = 0, num_c = 0, i, j;
struct container_buffer * shmptr;
char pn;
time_t now;
pid_t pid_p, pid_c;
printf("Main process starts.\n");
sem_id = semget(SEM_ALL_KEY, 2, IPC_CREAT | 0660);
semctl(sem_id, SEM_EMPTY, SETVAL, BUFFER_NUM);
semctl(sem_id, SEM_FULL, SETVAL, 0);
if ((shm_id = shmget(IPC_PRIVATE, BUF_LENGTH, SHM_MODE)) < 0)
{
exit(1);
}
if ((shmptr = shmat(shm_id, 0, 0)) == (void *)-1)
{
exit(1);
}
shmptr->head = 0;
shmptr->tail = 0;
shmptr->is_empty = 1;
while ((num_p++) < PRODUCER)
{
if ((pid_p = fork()) < 0)
{
exit(1);
}
if (pid_p == 0)
{
if ((shmptr = shmat(shm_id, 0, 0)) == (void *)-1)
{
exit(1);
}
下略 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询