monitor 제 06 강 : monitor. 세마포어의 문제점 코딩, 이해, 검증이 어렵다. 여러...
DESCRIPTION
Monitor 상호배제를 위한 abstract data type Monitor –shared data (hide) –critical sections int x; /*shared var*/ inc_x(); { } dec_x() { } Data ProceduresTRANSCRIPT
Monitor
제 06 강 : Monitor
세마포어의 문제점
• 코딩 , 이해 , 검증이 어렵다 . • 여러 사람의 자발적인 협조에 의존할 수 밖에 • 한 개의 오류가 전체 시스템에 악영향을 미친다 .
P(S); critical
sectionV(S); 일반 code P(M); critical
sectionV(M); 일반 code
P(Z); critical
sectionV(Z); 일반 code P(Q); critical
sectionV(Q); 일반 code
P(X); critical
sectionV(X); 일반 code P(Y); critical
sectionV(Y); 일반 code
P(S); critical
sectionV(S); 일반 code P(M); critical
sectionV(M); 일반 code
Monitor• 상호배제를 위한 abstract data type• Monitor
– shared data (hide)– critical sections
int x; /*shared var*/
inc_x();{ ----- ----- }
dec_x(){ ----- ----- }
Data
Procedures
Critical Section of n Processes
Process:
{ P(S); critical section V(S); 일반 code } while (1);
Critical Section of n Processes
Process:
{ P(S); critical section V(S); 일반 code } while (1);
int x; /*shared var*/
inc_x();{ ----- ----- }
dec_x(){ ----- ----- }
Process:
{ Call Monitor
일반 code } while (1);
Monitor• 동시 호출 ?
– 하나씩 차례대로 진입시킨다 . • wait()
– 모니터 안에서 block 될때• signal()
– 모니터 안에서 wakeup 시
int x; /*shared var*/
inc_x();{ ----- -wait()-- }
dec_x(){ ----- -signal()-- }
IPC(Inter Process
Communication)
Interprocess Communication (IPC)
• 두가지 방식 :– Shared memory – Message
• OS system call 을 통해
CPUMemory
P1
CPUMemory
OSOS
P3
Network
SharedMemory
P2
Interprocess Communication (IPC)
• 두가지 방식 :– Shared
memory – Message
SharedMemory
CPUMemory
P1
OS
P2
Producer-Consumer Problem
modulo operationring bufferprocess synchronizationOS system call
allocate shared memoryallocate semaphoreP(S) V(S)
아래한글produce
프린터 프로그램consume
os IPCsys call
IPCsys call
SharedMemory
CPUMemory
P1
OS
P2
Interprocess Communication (IPC)
• 두가지 방식 :– Shared memory – Message
• OS system call 을 통해서
CPUMemory
P1
CPUMemory
OSOS
P3
Network
CPUMemory
P1
CPUMemory
OSOS
P3
Network
Producer-Consumer Problem• 두가지 IPC System calls:
– send( 주소 , Message) – receive( 주소 , Message)
CPUMemory
P1
CPUMemory
OSOS
P3
Network
Producer-Consumer Problem• 두가지 IPC System calls:
– send( 주소 , Message) – receive( 주소 , Message)
• 직접통신
• 간접통신사서함 7 번
종로 12 번지
직접 통신 • 상대방 프로세스의 PID 사용
– system calls:•send(PID, message) •receive(PID, message)
• 문제 :– Compile 전에 상대방 PID 를 알 수 있어야– mailbox ( 우편 사서함 )
종로 12 번지
간접 통신 • 상대방 컴퓨터의 mailbox (port) 사용
– system calls:•port#=allocate_port() •send(port#, message) •receive(port#, message)
• 세계표준 port 번호 – web– email– ftp
사서함 7 번
CPUMemory
P1
CPUMemory
OSOSport
P3
Network
port