看板 Grad-ProbAsk 關於我們 聯絡資訊
※ 引述《liataian (柴油)》之銘言: : 板友好 想請教一下 : 中央有一題問說: : 為何spinlocks不適用於single-processor系統 : 而是常使用於multiprocessor系統 : 我去google了一下有goo到答案 題目一模一樣!? 如下 : Q:Why spinlocks are not appropriate for single-processor systems : yet are often used in multiprocessor systems? : A:"Spinlocks should not be used on single-processor systems. Consider a high : priority thread which attempts to claim a spinlock already held by a lower : priority thread: it will just loop forever and the lower priority thread will : never get another chance to run and release the spinlock. Even if the two : threads were running at the same priority, the one attempting to claim the : spinlock would spin until it was timesliced and a lot of cpu time would be : wasted. If an interrupt handler tried to claim a spinlock owned by a thread, : the interrupt handler would loop forever. Therefore spinlocks are only : appropriate for SMP systems where the current owner of a spinlock can : continue running on a different processor. " : 老實說有點有看沒有很懂 : 有板友能用淺顯一點的話幫我解釋一下嗎 謝謝> < : 還是說有更簡潔的說法 不用那麼複雜呢? 假如只有一個processor, process P1正霸占著CPU spin, 在P1的time slice之中解除spin的條件就永遠不能滿足(因為就只有P1自己在那邊spin), P1就在那邊一直spin spin spin spin... 直到P1的time slice用完, 這樣分配給P1的整個time slice就浪費掉了。 但是若有兩個以上的processors, process P1在processor A上spin, 在其他processors上同時執行的其他processes可能可以讓P1從spinlock中解脫, 這時P1可以繼續做些有用的事情,而不是浪費整個time slice在spin。 有錯誤的話還請多指正,謝謝 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.166.115.188
liataian:剛剛翻一下恐龍才發現原來這是恐龍題目 冏 09/15 20:12
jackbll:推~ 09/15 20:31
da0910cc: 09/15 22:23