공유 데이터에 대한 접근

Producer(생산자) , Consumer(소비자)

//생산자는 버퍼에 값이 차있는지 확인을 하고 다음 프로세스를 버퍼에 넣어야한다 오버 플로우 방지
int [] buffer = new int [10];
int count=0;
int in=0;
while(true)
{
	while(count == BUFFER_SIZE) ; //do nothing Full Checking

    buffer[in] = nextProduced;
    in = (in+1) % BUFFER_SIZE;
    count++;
}

//반대로 소비자는 버퍼에 값이 없는 경우 값을 읽으면 안된다
while(true)
{
	while(count == 0 ); // do nothing Empty Checking
    nextConsumed = buffer[out];
    out = (out+1) % BUFFER_SIZE;
    count--;
}

위 접근에 대한 문제점(Race Condition) 과 평가

Critical Section Problem을 해결하는 3가지 해결책

Problem 예시

  1. process(진행 조건) 문제
while turn != i //Pi 차례가 아님do skip;
   CS section //내차례가 되면 CS에 접근
turn = j; //다 실행을 하면 턴을 j로 바꿈
   RM section
until false;


flag[i] = true; //i가 들어가고싶다고 선언
while flag[j] do skip; // j가 들어가고싶다면 스킵
	CS Section

flag[i] = false;

	RM section