목차
1. 숙제 설명
2. 가정 설명
3. 프로그램 설명
4. 프로그램 실행 방법 및 결과 캡쳐
5. 소스 파일 첨부
2. 가정 설명
3. 프로그램 설명
4. 프로그램 실행 방법 및 결과 캡쳐
5. 소스 파일 첨부
본문내용
이 생산자 역할이고 , cpu(프로그램)이 소비자이며
//write작업일 때는 io채널이 소비자 역할이고, cpu(프로그램)이 생산자 역할이다.
//즉 두 함수는 결과적으로 본체가 똑같으며 각각 생산자와 소비자 역할 부분을 모두 가지고 있는 함수이다.
//인수로 전달받는 rw변수에 의해 각각의 함수가 생산자와 소비자 역할을 따로 수행하게 된다.
//io채널 역할을 하는 함수
void iochannel(int rw, int count){
float percent;//작업 정도(%)를 출력하기 위해 선언된 변수
if(rw==1){//생산자의 역할 부분
if(to_fill->full_flag!=1){//채워야 될 버퍼가비었다면
if(to_fill->record_counter==blocking_factor){//버퍼가 다 찼는지 확인해서
if(waitc1=1)
waitc1=0;
to_fill->record_counter=0;//다 찼다면 record_counter변수를 바꾸고
to_fill->full_flag=1;//찼다는 것을 full_flag변수를 1로 바꾸어서 표시하고
fprintf(processfp,"iochannel filled buffer%d.\n",to_fill->check);//출력한다음
to_fill=to_fill->next_buffer;//채울곳이 다음 버퍼임을 표시한다.
}else{//버퍼가 다 차지 않았다면
to_fill->data[to_fill->record_counter]=(int)fgetc(readfp);//채워야 될 곳에 데이터를 채운다
to_fill->record_counter++;//record_counter변수를 1증가시킨다.
}
}else if(to_fill->full_flag==1&&waitc1==0){//채워야할 버퍼가 차있다면
fprintf(processfp,"iochannel is waiting until buffer is empty.\n");//비워질때까지 대기한다.
waitc1=1;
}
}else{//소비자의 역할 부분
if(to_empty->full_flag!=0){//비워야할 버퍼가 채워져 있다면
if(count%call_delay==0){//n번째 명령이 왔을때
if(waitc1=1)
waitc1=0;
fputc((int)to_empty->data[to_empty->record_counter],writefp);//버퍼에서 작업영역으로 옮긴다.
to_empty->record_counter++;//record_counter을 1감소시킨다.
if(to_empty->record_counter==blocking_factor){//만약 다 비웠다면
to_empty->full_flag=0;//full_flag를 0으로 하고
to_empty->record_counter=0;//record_counter도 0으로 하고
fprintf(processfp,"iochannel emptied buffer%d.\n",to_empty->check);//출력한다음
to_empty=to_empty->next_buffer;//다음 비울 버퍼를 가리키고
now+=blocking_factor;//처리한 데이터를 변수에 저장해서
percent=((float)now/(float)record_number)*100;//처리한 작업량을
fprintf(processfp,"---%.2fpercent processed.\n",percent);//출력한다.
}}
}else if(to_empty->full_flag==0&&waitc1==0){
fprintf(processfp,"iochannel is waiting until buffer is full.\n");
waitc1=1;
}
}
}
//cpu(프로그램) 역할을 하는 함수
void utility(int rw,int count){
float percent;
if(rw==2){
if(to_fill->full_flag!=1){
if(to_fill->record_counter==blocking_factor){
if(waitc2=1)
waitc2=0;
to_fill->full_flag=1;
to_fill->record_counter=0;
fprintf(processfp,"cpu(utility) filled buffer%d.\n",to_fill->check);
to_fill=to_fill->next_buffer;
}else{
to_fill->data[to_fill->record_counter]=(int)fgetc(readfp);
to_fill->record_counter++;
}
}else if(to_fill->full_flag==1&&waitc2==0){
fprintf(processfp,"cpu(utility) is waiting until buffer is empty.\n");
waitc2=1;
}
}else{
if(to_empty->full_flag!=0){
if(count%call_delay==0){
if(waitc2=1)
waitc2=0;
fputc((int)to_empty->data[to_empty->record_counter],writefp);
to_empty->record_counter++;
if(to_empty->record_counter==blocking_factor){
to_empty->full_flag=0;
to_empty->record_counter=0;
fprintf(processfp,"cpu(utility) emptied buffer%d.\n",to_empty->check);
to_empty=to_empty->next_buffer;
now+=blocking_factor;
percent=((float)now/(float)record_number)*100;
fprintf(processfp,"---%.2fpercent processed.\n",percent);
}}
}else if(to_empty->full_flag==0&&waitc2==0){
fprintf(processfp,"cpu(utility) is waiting until buffer is full.\n");
waitc2=1;
}
}
}
//write작업일 때는 io채널이 소비자 역할이고, cpu(프로그램)이 생산자 역할이다.
//즉 두 함수는 결과적으로 본체가 똑같으며 각각 생산자와 소비자 역할 부분을 모두 가지고 있는 함수이다.
//인수로 전달받는 rw변수에 의해 각각의 함수가 생산자와 소비자 역할을 따로 수행하게 된다.
//io채널 역할을 하는 함수
void iochannel(int rw, int count){
float percent;//작업 정도(%)를 출력하기 위해 선언된 변수
if(rw==1){//생산자의 역할 부분
if(to_fill->full_flag!=1){//채워야 될 버퍼가비었다면
if(to_fill->record_counter==blocking_factor){//버퍼가 다 찼는지 확인해서
if(waitc1=1)
waitc1=0;
to_fill->record_counter=0;//다 찼다면 record_counter변수를 바꾸고
to_fill->full_flag=1;//찼다는 것을 full_flag변수를 1로 바꾸어서 표시하고
fprintf(processfp,"iochannel filled buffer%d.\n",to_fill->check);//출력한다음
to_fill=to_fill->next_buffer;//채울곳이 다음 버퍼임을 표시한다.
}else{//버퍼가 다 차지 않았다면
to_fill->data[to_fill->record_counter]=(int)fgetc(readfp);//채워야 될 곳에 데이터를 채운다
to_fill->record_counter++;//record_counter변수를 1증가시킨다.
}
}else if(to_fill->full_flag==1&&waitc1==0){//채워야할 버퍼가 차있다면
fprintf(processfp,"iochannel is waiting until buffer is empty.\n");//비워질때까지 대기한다.
waitc1=1;
}
}else{//소비자의 역할 부분
if(to_empty->full_flag!=0){//비워야할 버퍼가 채워져 있다면
if(count%call_delay==0){//n번째 명령이 왔을때
if(waitc1=1)
waitc1=0;
fputc((int)to_empty->data[to_empty->record_counter],writefp);//버퍼에서 작업영역으로 옮긴다.
to_empty->record_counter++;//record_counter을 1감소시킨다.
if(to_empty->record_counter==blocking_factor){//만약 다 비웠다면
to_empty->full_flag=0;//full_flag를 0으로 하고
to_empty->record_counter=0;//record_counter도 0으로 하고
fprintf(processfp,"iochannel emptied buffer%d.\n",to_empty->check);//출력한다음
to_empty=to_empty->next_buffer;//다음 비울 버퍼를 가리키고
now+=blocking_factor;//처리한 데이터를 변수에 저장해서
percent=((float)now/(float)record_number)*100;//처리한 작업량을
fprintf(processfp,"---%.2fpercent processed.\n",percent);//출력한다.
}}
}else if(to_empty->full_flag==0&&waitc1==0){
fprintf(processfp,"iochannel is waiting until buffer is full.\n");
waitc1=1;
}
}
}
//cpu(프로그램) 역할을 하는 함수
void utility(int rw,int count){
float percent;
if(rw==2){
if(to_fill->full_flag!=1){
if(to_fill->record_counter==blocking_factor){
if(waitc2=1)
waitc2=0;
to_fill->full_flag=1;
to_fill->record_counter=0;
fprintf(processfp,"cpu(utility) filled buffer%d.\n",to_fill->check);
to_fill=to_fill->next_buffer;
}else{
to_fill->data[to_fill->record_counter]=(int)fgetc(readfp);
to_fill->record_counter++;
}
}else if(to_fill->full_flag==1&&waitc2==0){
fprintf(processfp,"cpu(utility) is waiting until buffer is empty.\n");
waitc2=1;
}
}else{
if(to_empty->full_flag!=0){
if(count%call_delay==0){
if(waitc2=1)
waitc2=0;
fputc((int)to_empty->data[to_empty->record_counter],writefp);
to_empty->record_counter++;
if(to_empty->record_counter==blocking_factor){
to_empty->full_flag=0;
to_empty->record_counter=0;
fprintf(processfp,"cpu(utility) emptied buffer%d.\n",to_empty->check);
to_empty=to_empty->next_buffer;
now+=blocking_factor;
percent=((float)now/(float)record_number)*100;
fprintf(processfp,"---%.2fpercent processed.\n",percent);
}}
}else if(to_empty->full_flag==0&&waitc2==0){
fprintf(processfp,"cpu(utility) is waiting until buffer is full.\n");
waitc2=1;
}
}
}
소개글