or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
OS筆記-Chapter 6: Process Synchronization
tags:
OS
目錄
Chapter 1: Introduction
Chapter 2: Operating-System Structures
Chapter 3: Processes
Chapter 4: Threads
Chapter 5: CPU Scheduling
Chapter 6: Process Synchronization
Chapter 7: Deadlocks
Chapter 8: Main Memory
Chapter 9: Virtual Memory
Chapter 10: File-System Interface
Chapter 11: File System Implementation
Chapter 12: Mass-Storage Systems
Chapter 13: I/O Systems
Chapter 14: Protection
Chapter 15: Security
背景
競爭情況(race condition):多個行程並行處理資料
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →需要行程同步(Process Synchronization)和協調(coordination)
臨界區間問題(Critical Section Problem)
臨界區間:
解決臨界區間問題
假設n個行程執行速度不為零
可搶先核心(preemptive kernel)
不可搶先核心(nonpreemptive kernel)
Peterson Solution
同步之硬體(Synchronization Hardware)
使用鎖(lcok)保護臨界區間
單一處理器:
多處理器:
互斥鎖(Mutex Locks)
mutex = mutual exclusion
使用互斥鎖保護臨界區間
忙碌等待(busy waiting):

號誌(semaphore)
S為號誌的值,同時只能有一個行程修改此值

技術號誌(Counting semaphore):不受限制
二元號誌(Binary semaphore):0或1
號誌被設定為可用資源數字的初值
為了解決這種忙碌等待的需要
如果號誌的值為負的,其大小則為等待此號誌的行程數目
死結(deadlocked)
無限期阻滯(– indefinite blocking)/飢餓(Starvation)
優先權倒置(Priority Inversion)
典型的同步問題
有限緩衝區問題(Bounded-Buffer Problem)
讀取者-寫入者問題(Readers-Writers Problem)
哲學家進餐問題(Dining-Philosophers Problem)

監督程式(Monitors)
一種抽象資料型態(ADT,abstract data type),且監督程式內設有互斥

可以確保只有一個行程在監督程式內活動

可定義一個或多個條件變數
使用監督程式解決哲學家進餐問題

使用號誌製作監督程式
監督程式內的恢復行程
替代方法
交易記憶體(transactional memory):是一連串不可分割的記憶體讀取和寫入操作,如果一個交易中所有交易都被完成,則記憶體被交付,否則操作被終止並撤回
軟體交易記憶體(STM,software transactional memory):
硬體交易記憶體(HTM,hardware transactional memory)
命令式(imperative)/程序(procedure)程式語言
功能性(functional)程式語言