Re: [問題] 聽說kernel code 不會被interrupt...

作者: Artoo (artoo)   2008-12-17 09:05:54
因為Print的實作內會用到Semaphore
1. Print在呼叫kernel->synchConsoleOut->PutChar()時
這裡面的Lock會關閉、開啟interrupt,其中開啟時會呼叫OneTick
就是這裡可能會產生context switch
2. SynchConsoleOutput::PutChar()本身每送出一個字元,就會停下來等
這個字元真的被畫在螢幕上(一個硬體interrupt,不過這裡只是模擬)
就是waitFor->P()那一列
所以這裡也會context switch
另外,請勿在Print內使用printf、putchar、cout或任何類似的東西
測試可以,但交作業前請務必更改回來
否則會扣分
※ 引述《robertshih (施抄)》之銘言:
: 但是在multi-program的情況下
:
: Print system call(應該是kernel code)如果沒有被semaphore保護
:
: 為何會產生syncronization的問題
:
: ex.
:
: Process 1:
: Print("ABC");
:
: Process 2:
: Print("DEF");
:
: output:
: ADEBCF
:
:

Links booklink

Contact Us: admin [ a t ] ucptt.com