10주차.key

Similar documents
Module 7: Process Synchronization

Microsoft PowerPoint - o6.pptx

Microsoft PowerPoint - o6.pptx

Module 7: Process Synchronization

Microsoft PowerPoint - o6.pptx

Microsoft PowerPoint - StallingsOS6e-Chap05.pptx

Synchronization

6주차.key

Abstract View of System Components

untitled

Chap06(Interprocess Communication).PDF

K&R2 Reference Manual 번역본

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

chap 5: Trees

Microsoft PowerPoint - StallingsOS6e-Chap06.ppt [호환 모드]

chap01_time_complexity.key

untitled

쓰레드 (Thread) 양희재교수 / 경성대학교컴퓨터공학과

Microsoft Word - ExecutionStack

UI TASK & KEY EVENT

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

고급동기화및프로세스간통신

Embeddedsystem(8).PDF

PowerPoint 프레젠테이션

CompareAndSet(CAS) 함수는 address 주소의값이 oldvalue 인지비교해서같으면 newvalue 로 바꾼다. 소프트웨어 lock 을사용하는것이아니고, 하드웨어에서제공하는기능이므로더빠르고 간편하다. X86 에서는 _InterlockedCompareEx

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

Oracle9i Real Application Clusters

Chapter #01 Subject

3주차_Core Audio_ key

Chapter 4. LISTS

07 자바의 다양한 클래스.key

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M.

Chapter 4. LISTS

C# Programming Guide - Types

Operating System Lab 2

23

Modern Javascript

C프로-3장c03逞풚

Line (A) å j a k= i k #define max(a, b) (((a) >= (b))? (a) : (b)) long MaxSubseqSum0(int A[], unsigned Left, unsigned Right) { int Center, i; long Max

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

ESP1ºÎ-04

13주-14주proc.PDF

Chapter 4. LISTS

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

강의10

OCaml

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures

비긴쿡-자바 00앞부속

chap8.PDF

PRO1_09E [읽기 전용]

untitled

11강-힙정렬.ppt

chap7.key

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

PowerPoint 프레젠테이션

Motor

Microsoft PowerPoint - RMI.ppt

Chap04(Signals and Sessions).PDF

03장.스택.key

텀블러514

MPLAB C18 C

5.스택(강의자료).key

MAX+plus II Getting Started - 무작정따라하기

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

T100MD+

MS-SQL SERVER 대비 기능

11장 포인터

SRC PLUS 제어기 MANUAL

untitled

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형


4.18.국가직 9급_전산직_컴퓨터일반_손경희_ver.1.hwp

歯엑셀모델링

untitled

RVC Robot Vaccum Cleaner

03_queue

슬라이드 1

Microsoft PowerPoint - polling.pptx

09-interface.key

Lab 4. 실습문제 (Circular singly linked list)_해답.hwp

12-file.key

Microsoft PowerPoint - es-arduino-lecture-03

제4장 기본 의미구조 (Basic Semantics)

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

thesis


chap x: G입력

ºÎ·ÏB

Jerry Held

슬라이드 1

<4D F736F F F696E74202D20C1A63132B0AD20B5BFC0FB20B8DEB8F0B8AEC7D2B4E7>


The Self-Managing Database : Automatic Health Monitoring and Alerting

Lab 3. 실습문제 (Single linked list)_해답.hwp

10.

2 / 26

Remote UI Guide

Microsoft PowerPoint - hw8.ppt [호환 모드]

Transcription:

10,

Process synchronization (concurrently) ( ) => critical section ( ) / =>, A, B /

Race condition int counter; Process A { counter++; } Process B { counter ;.. } counter++ register1 = counter register1 = register1 + 1 counter= register1 counter register2 = counter register2 = register2-1 counter = register2

Race condition When initially count = 5 S0: PA register1 = counter (register1 = 5) S1: PA register1 = register1+1 (register1 = 6) S2: PB register2 = counter (register2 = 5) S3: PB register2 = register2-1 (register2 =4) S4: PA counter = register1 (counter = 6) S5: PB counter = register2 (counter = 4)

Critical section problem => wait

Critical section

Solution to critical section problem Mutual exclusion Progress remainder section CS, Bounded waiting A,,, A =>

Peterson s solution For two processes int turn; boolean flag[2]; turn: CS? flag: flag[i] = true, i CS

Algorithm for process Pi do { flag[i] = true; turn = j; // process j CS while (flag[j] && turn == j); critical section flag[i] = false; remainder section } while (true);, turn=i, turn=j, turn =>, turn => CS (flag[i], flag[j] true ) => mutual exclusion CS flag[] false, while() CS => progress, bounded-waiting

Peterson s solution Pi do { flag[i] = true; turn = j; while (flag[j] && turn == j); critical section flag[i] = false; remainder section } while (true); Pj do { flag[j] = true; turn = i; while (flag[i] && turn == i); critical section flag[j] = false; remainder section } while (true);

Synchronization Hardware support for CS code Protecting CS via locks Uniprocessor system Multiprocessor system hardware =>? => atomic operation => API while (test_and_set(&lock)) ; //do nothing // critical section lock test_and_set => atomic

Bounded-waiting mutual exclusion with test_and_set do { waiting[i] = true; key = true; while (waiting[i] && key) key = test_and_set(&lock); waiting[i] = false; /* critical section */ j = (i + 1) % n; while ((j!= i) &&!waiting[j]) j = (j + 1) % n; if (j == i) else lock = false; waiting[j] = false; /* remainder section */ } while (true); process queue CS waiting[j] = false (lock )., CS (if (j ==i)) lock waiting[] true => mutual exclusion, progress, bounded-waiting

Mutex locks (test_and_set) acquire(), release() Atomic via hardware implementation Busy waiting Spinlock

Mutex locks acquire() { while (!available) } ; /* busy wait */ available = false;; release() { } available = true; do { acquire lock critical section release lock remainder section } while (true);

Semaphore Busy waiting S: semaphore variable, integer Counting semaphore: S >= 0 Binary semaphore: S = 0 or 1 wait(), signal() Should be implemented atomically wait() signal() - wait() CS semaphore list semaphore list wait signal() semaphore list ready

Semaphore P1 and P2 that require S1 to happen before S2 P1: S1; signal(synch); P2: wait(synch); S2;

Semaphore typedef struct{ int value; struct process *list; } semaphore; wait(semaphore *S) { } S->value--; if (S->value < 0) { add this process to S->list; } block(); signal(semaphore *S) { } S->value++; if (S->value <= 0) { remove a process P from S->list; } wakeup(p);

Deadlock and Starvation Let S and Q be two semaphore initialized to 1 P0: wait(s); wait(q); signal(s); signal(q); P1: wait(q); wait(s); signal(q); signal(s); P0 wait(s), P1 signal(s), P1 wait(q) P0 signal(q) => Deadlock!!

Classic problems of synchronization Bounded-buffer problem Readers and writers problem Dining philosophers problem

Bounded-buffer problem n item mutex: 1, full: 0, => empty empty: n, => full The structure of the producer process The structure of the consumer process do {... /* produce an item in next_produced */... wait(empty); wait(mutex);... /* add next produced to the buffer */... signal(mutex); signal(full); } while (true); do { wait(full); wait(mutex);... /* remove an item from buffer to next_consumed */... signal(mutex); signal(empty);... /* consume the item in next consumed */... } while (true);

Readers-writers problem concurrent process ( ) Readers - Writers - reader writer starvation Shared data Data set Semaphore rw_mutex: 1, writer Semaphore mutex: 1, read_count Integer read_count: 0

Readers-writers problem writer CS writer reader CS reader writer writer The structure of a writer process do { writer reader CS wait(rw mutex);... /* writing is performed */... signal(rw mutex); } while (true); The structure of a reader process do { wait(mutex); read_count++; if (read count == 1) wait(rw mutex); signal(mutex);... /* reading is performed */... wait(mutex); read count--; if (read count == 0) signal(rw mutex); signal(mutex); } while (true); - read_count 1 reader writer CS (wait(rw_mutex)) - read_count 1 reader CS - read_count 0 CS reader,, writer

Dining-philosophers problem : 6-14? Deadlock, 4

Monitor High-level abstraction Java, C# procedure => Monitor Monitor monitor monitor-name { // shared variable declarations procedure P1() { } procedure P2() { } procedure P3() { } initialization_code () { } }

Monitor

condition variables Monitor condition x; x.wait(), x.signal()

Monitor x

Monitor Solution to dining-philosophers monitor DiningPhilosophers { enum { THINKING; HUNGRY, EATING) state [5] ; condition self [5]; void pickup (int i) { state[i] = HUNGRY; test(i); if (state[i]!= EATING) self [i].wait; } test(i) HUNGRY void putdown (int i) { state[i] = THINKING; // test left and right neighbors test((i + 4) % 5); test((i + 1) % 5); } } void test (int i) { if ( (state[(i + 4) % 5]!= EATING) && (state[i] == HUNGRY) && (state[(i + 1) % 5]!= EATING) ) { state[i] = EATING ; self[i].signal () ; }, } initialization_code() { for (int i = 0; i < 5; i++) state[i] = THINKING; }

Each processor i Monitor DiningPhilosophers.pickup(i); EAT DiningPhilosophers.putdown(i) Monitor deadlock,, starvation? HW #4

Pthread #include <pthread.h> pthread mutex_t mutex; pthread mutex_init(&mutex, NULL); pthread mutex_lock(&mutex); pthread mutex_unlock(&mutex); #include <semaphore.h> sem_t sem; sem_init(&sem, 0, 1); sem_wait(&sem); sem_post(&sem);

HW #5 P.347 2