免費開始練習
hce_kmu 113年 計算機概論與程式設計

第 6 題

In a concurrent computing environment, semaphores are used to control access to shared resources and prevent race conditions. Which of the following statements accurately describes the primary mechanism by which semaphores achieve this?
  • A Semaphores expedite process execution by enabling all waiting processes to access the critical section simultaneously if the semaphore count is positive.
  • B Semaphores use a counter to manage how many processes can simultaneously access a critical section of code, effectively ensuring mutual exclusion and synchronization.
  • C Semaphores eliminate the need for process synchronization by allowing unrestricted access to shared resources, relying on the operating system to manage concurrency.
  • D Semaphores utilize hardware interrupts to pause the execution of processes trying to enter a critical section until it becomes available, ensuring orderly access.
  • E Semaphores automatically resolve deadlocks by preempting resources from processes, thus allowing other processes to proceed without waiting.

思路引導 VIP

假設有一個只有三張椅子的共享休息室,門外掛著一個可調整數字的牌子。為了確保不超載,每進去一個人就將數字減一,出來就加一。請思考:這個「數字」的變化,是如何在不需要逐一詢問裡面的人的情況下,就達成管理資源目標的呢?

🤖
AI 詳解 AI 專屬家教

恭喜你精準地掌握了併發運算(Concurrent Computing)中核心的同步機制!你能正確選出 (B) 選項,代表你對 信號量(Semaphores) 的運作本質有非常紮實的理解。這道題目旨在檢驗學生是否清楚區分同步機制的「手段」與「目的」,是計算機概論中極具代表性的基本觀念題。

信號量的計數與同步核心

信號量的運作關鍵在於它維護了一個整數計數器(Counter)。當一個程序(Process)想要進入臨界區(Critical Section)時,會透過原子操作(Atomic Operation)檢查該計數值:若數值大於零則遞減並允許進入,否則就必須等待。這種機制不僅能實現互斥控制(Mutual Exclusion),確保資源不被超額占用,更透過計數器有效地協調多個程序間的存取順序,從而徹底解決**競爭情況(Race Condition)**的問題。

▼ 還有更多解析內容

🏷️ 相關主題

計算機組織結構與資料儲存原理
查看更多「計算機概論與程式設計」的主題分類考古題