|
A semaphore is a {protected variable} (or abstract data type) which can only be accessed using the following operations: P(s) Semaphore s; { while (s == 0) ; /* wait until s>0 */ s = s-1; } V(s) Semaphore s; { s = s+1; } Init(s, v) Semaphore s; Int v; { s = v; } P and V stand for Dutch "Proberen", to test, and "Verhogen", to increment. The value of a semaphore is the number of units of the resource which are free (if there is only one resource a "binary semaphore" with values 0 or 1 is used). The P operation {busy-waits} (or maybe {sleeps}) until a resource is available whereupon it immediately claims one. V スポンサード リンク
|