资源简介
仅供参考,被查雷同概不负责
sys.h
unistd.h
system_call.s
sem.c
shm.c
memory.c
producer.c
consumer.c
report.txt
代码片段和文件信息
#define __LIBRARY__
#include
#include
#include
#include
#include
#include
#define N 600
#define BUFFSIZE 10
_syscall2(intsem_open const char* name unsigned int value)
_syscall1(int sem_wait sem_t * sem)
_syscall1(int sem_post sem_t * sem)
_syscall1(int sem_unlink const char * name)
_syscall2(int shmget key_t key size_t size)
_syscall2(void * shmat int shmid const void* shmaddr)
int main()
{
int shmid pread i;
int * buff;
sem_t *empty *full *mutex;
empty = (sem_t *)sem_open(“empty“10);
full = (sem_t *)sem_open(“full“ 0);
mutex = (sem_t *)sem_open(“mutex“ 1);
pread = 0;
shmid = shmget((key_t)12 BUFFSIZE*sizeof(int));
if(!shmid)
{
printf(“shmget failed!“);
fflush(stdout);
exit(0);
}
buff = (int*)shmat(shmidNULL);
if(!buff)
{
printf(“shmat failed!“);
fflush(stdout);
exit(0);
}
for( i = 0 ; i < N; i++)
{
sem_wait(full);
sem_wait(mutex);
printf(“^@^ %d\n“ buff[pread]);
fflush(stdout);
pread = ( pread + 1)% BUFFSIZE;
sem_post(mutex);
sem_post(empty);
}
sem_unlink(“empty“);
sem_unlink(“full“);
sem_unlink(“mutex“);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1358 2009-12-23 12:03 lab 5\consumer.c
文件 11173 2009-12-23 12:04 lab 5\memory.c
文件 1228 2009-12-23 12:04 lab 5\producer.c
文件 7156 2009-12-23 12:04 lab 5\report(3).txt
文件 2927 2009-12-23 12:04 lab 5\sem(2).c
文件 796 2009-12-23 12:04 lab 5\shm.c
文件 2828 2009-12-23 12:04 lab 5\sys(3).h
文件 5229 2009-12-23 12:04 lab 5\system_call(3).s
文件 6868 2009-12-23 12:04 lab 5\unistd(3).h
目录 0 2011-11-07 14:06 lab 5
----------- --------- ---------- ----- ----
39563 10
评论
共有 条评论