Computing/Operating System

09 > 동기화(1)

i독 2021. 11. 15. 02:14

* 해당 게시물은 경북대학교 컴퓨터학부 강의초빙교수, 배준현 교수님의 강의를 보고 작성되었음을 미리 알려드립니다. ( 개인적인 공부를 정리한 글입니다. )

 

> 주니온 TV Youtube Channel.  https://www.youtube.com/channel/UCOcPzXDWSrnaKXse9XOPiog

 

주니온TV 아무거나연구소

TMI Lab. 아무거나 연구소의 유튜브 TMI 지식나눔 채널 컴퓨팅 사고력을 키워 주고 코딩 지능을 길러 주는 자세히 보면 유익한 코딩 채널 주니온TV@Youtube 주니온 박사: 현) 경북대학교 컴퓨터학부 초

www.youtube.com

 

> 주니온 TV Inflearn page.  https://www.inflearn.com/users/@joonion

 

주니온님의 소개 - 인프런 | 온라인 강의 플랫폼

인프런 지식공유자 주니온님의 소개 페이지 입니다. - 지식공유자 소개 | 인프런...

www.inflearn.com


[  ] Data inconsistency

- Although two processes are correct separately,

  they may not function correctly when executed concurrently.

 

- How these results can happen?

  Note that two statements “count++” and “count--”

  + may be implemented in machine language as follows:

  Even though register1 and register2 may be the same physical register, the contents of these registers will be saved and restored by the interrupt handler (or scheduler).

, Context switch 발생하는 구간이 Random이기에, 값이 처리 되는 중간에 발생하면 명령이 잘못 수행되어 count 잘못된 값으로 저장될 있다.

임의적인 순서로 실행되면 위와 같이 값이 잘못 되버린다. 이러한 상황을 Race Condition이라 한다.

 

[] Race Condition

- A situation

  where several processes (or threads)

  access and manipulate the same (or shared) data concurrently

  and the outcome of the execution

  depends on the particular order in which the access takes place.

 

- To guard against the race condition, To guard against the race condition,

  + We need to ensure that only one process at a time can manipulate the shared data.

  + To make such a guarantee, we require that the processes are synchronized in some way. to say, process (or thread) synchronization.

데이터를 처리할 때는 개의 process 다룰 있게끔 만든다. > 순차적인 순서로 실행하는 것이 가능하게 된다.

 

[] The Critical Section Problem: 임계영역 설정해서 해결한다.

- The important feature of the system is that, when one process is executing in its critical section, no other process is allowed to execute in its critical section.

 

-Sections of codes:

 + The entry-section: the section of code to request permission to enter its critical section.

 + The critical-section follows the entry-section.

 + The exit-section follows the critical-section.

 + The remainder-section is the section of remaining code.

 

- Three requirements for the solution:

 + Mutual Exclusion(상호 배제): If process Pi is executing in its critical section, then no other processes can be executing in their critical section.

상호 배제를 하게 된다면 2가지의 문제가 발생한다.

 + Progress: (avoid deadlock) : If no process is executing in its critical section and some processes wish to enter their critical section, then the selection of next process will enter its critical section next cannot be postponed indefinitely.

Critical section 아무도 진입할 없는 상황을 만들지 않는다.

 + Bounded Waiting: (avoid starvation) : A bound (or limit) on the number of times that other processes are allowed to enter

their critical sections after a process has made a request to enter its critical section and before that request is granted.

Critical section 계속해서 밀려 들어올 없는 프로세스가 발생하는 상황을 만들지 않는다.

Figure 6.2 Race co n dition when assigning a pid.

싱글 코어 환경일 , 가장 간단한 방법은 interrupts 막는 것이다. , 공유메모리에 접근하고 LOAD - Calculation - STORE 때에 interrupt disable 시키는 것이다.

다만 방법은 멀티 코어에서 성능을 매우 저하시킨다. shared data 접근하려는 다른 프로세스들은 모두 대기해버린다.

 

- Two general approaches

  + Non-preemptive kernel a kernel-mode process will run until it exits kernel mode, blocks, or voluntarily yields the CPU.   

     Essentially free from race conditions on kernel data structures.

Context switch 발생시키지 않는 , 역시 간단하지만 성능 저하 때문에 쓰이질 않는다.

  + Preemptive kernel allows a process to be preempted when it is running in kernel mode.

     Essentially difficult to design, but favorable since it may be more responsive.

 

[  ] Peterson's Algorithm

- a classic software solution to the critical-section problem.

- no guarantees that Peterson’s solution will work correctly, since modern computers perform basic machine-language instructions such as load and store.

 

- restricted to two processes that alternate execution between their critical sections and remainder sections.

Figure 6.3 The structure of pr o cess Pi   in Peters o n’s solution.

방법은 Guarantees 보장할 없다. 기계적 레벨에서 바라본다면 이유를 찾을 있다.

Critical section이라 지정한 외에도 지속적으로 데이터를 공유하는 곳이 있다.

Flag 변수가 바뀌는 , turn 변수를 바뀌는 , Flag Turn 확인하는 같은 과정이 제대로 동작하지 않는다.

 

- However, Peterson’s solution provides a good algorithmic description of solving the CSP.

  Illustrates some of the complexities involved in the requirements of mutual exclusion, progress, and bounded waiting.

 

[  ] Atomicity

- An atomic operation is one uninterruptible unit of operation.

- Modern computer systems provide special hardware instructions i.e., atomic instructions that allow us either to test and modify the content of a word or to test and swap the contents of two words

clock(core 한번에 처리할 있는 단위) 여러 개인 작업을 clock 처리 있게 회로를 수정한다.

 

[  ] Atomic Variable

위의 개념으로 함수를 만들 있다. 그리고 이것을 Java library에서 제공해준다. > Atomic variable.

'Computing > Operating System' 카테고리의 다른 글

11 > 동기화(3)  (0) 2021.11.15
10 > 동기화(2)  (0) 2021.11.15
08 > CPU scheduling  (0) 2021.11.15
06 - 07 > Thread [쓰레드, 멀티 쓰레딩]  (0) 2021.11.07
03 - 05 > Process [프로세스의 이해, 생성, 통신]  (0) 2021.11.07