⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outshm.h

📁 一个编程中常用的PV操作(生产者—消费者)的c语言的demo
💻 H
字号:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <string.h>

struct exchange
{
	char buf[BUFSIZE+80];//要交换的数据
	int seq;            //客户填入的顺序号
}
int open_semaphore_set(key_t, int);
void init_a_semaphore(int, int, int);
int semaphore_P(int);
int semaphore_V(int);
//创建/打开共享存储段,连接它到用户地址空间,返回它在用户空间的地址
unsigned char *shminit(key_t key)
{
	int shmid;
	unsigned char *retval;
	if ((shmid = shmget(key, sizeof(struct exchange),0666|IPC_CREAT)) == -1)
	{
		prinf("shmget error!\n");
		exit(0);
	}
	if ((retval = shmat(shmid,(unsigned char *)0, 0)) == (unsigned char *)-1)
	{
		prinf("shmat error!\n");
		exit(0);
	}
	return retval;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -