顯示具有 OS 標籤的文章。 顯示所有文章
顯示具有 OS 標籤的文章。 顯示所有文章

2010年12月21日 星期二

Semaphore

function V(semaphore S):
    Atomically increment S
    [S ← S + 1]

function P(semaphore S):
    repeat:
        Between repetitions of the loop other processes may operate on the semaphore
        [if S > 0:
            Atomically decrement S - note that S cannot become negative
            S ← S - 1
            break]

Monitor

The trend in programming language development is towards more structured forms of synchronization, such as monitors. These synchronization abstractions usually employ semaphores or mutexes internally, but do not expose the semaphore interface directly to the programmer. This is motivated partly by the serious, hard-to-diagnose problems that often arise when semaphores are used incorrectly, a risk much reduced when synchronization is tightly coupled to the resource it controls and is managed automatically by the language implementation rather than manually by the programmer.