0
確定線性化順序的確切程度。怎麼可以說下面的代碼的線性化順序是由wait()發佈的順序。 如何檢查代碼是否可線性化?確定線性化順序
class Buffer
{
int in = 0;
int out = 0;
int numElems = 0;
synchronized void put(E elem) throws InterruptedException
{
while (!numElems < N)
{
wait();
}
buff[in] = elem;
in = (in + 1) % N;
notifyAll();
}
synchronized E take() throws InterruptedException
{
while (!numElems > 0)
{
wait();
}
E temp = buff[out];
out = (out + 1) % N;
return temp;
notifyAll();
}
}
是預期的格式?很難閱讀。 – 2010-12-11 04:30:45
已將代碼格式化。 – devnull 2010-12-11 04:35:58