91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡(jiǎn)介

Linux C語(yǔ)言 實(shí)現(xiàn)利用多進(jìn)程或多線程模擬實(shí)現(xiàn)生產(chǎn)者/消費(fèi)者問(wèn)題。 (站在巨人的肩膀上)

資源截圖

代碼片段和文件信息

#include??
#include??
#include?
#include?

#define?SIZE?15
?
static?sem_t?mutex;??
static?sem_t?fullempty;?

struct?product{?
????char?products[SIZE];?
????int?firstend;?
????int?num;?????????????????
};
struct?product?*p;

void?*producter()?
{
char?c;
while(1){?
sem_wait(&empty);?
??? sem_wait(&mutex);
c=‘a(chǎn)‘+rand()?%?26;
p->products[p->end]=c;
p->end=(p->end+1)%SIZE ;
p->num=p->num+1;
printf(“proceducer生產(chǎn)了%c.........產(chǎn)品總數(shù)為%d\n“cp->num);?????
sem_post(&mutex);
sem_post(&full);
sleep(rand()%3);
}???????????
}

void?*consumer()?
?{
char?c;
while(1){?
sem_wait(&full);?
??? sem_wait(&mutex);
c=p->products[p->first];
p->first=(p->first+1)%15;
p->num=p->num-1;
printf(“consu

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????1370??2012-12-30?19:28??dd\dd.c
?????文件?????????111??2012-12-30?19:33??dd\操作說(shuō)明.txt
?????目錄???????????0??2012-12-30?19:34??dd\

評(píng)論

共有 條評(píng)論