これはリーダー/ライターの実装です。つまり、多くのリーダーは読み取ることができますが、一度に書き込むことができるライターは 1 つだけです。これは期待どおりに機能しますか?
public class ReadersWriters extends Thread{
static int num_readers = 0;
static int writing = 0;
public void read_start() throws InterruptedException {
synchronized(this.getClass()) {
while(writing == 1) wait();
num_readers++;
}
}
public void read_end() {
synchronized(this.getClass()) {
if(--num_readers == 0) notifyAll();
}
}
public void write_start() throws InterruptedException{
synchronized(this.getClass()) {
while(num_readers > 0) wait();
writing = 1;
}
}
public void write_end() {
this.getClass().notifyAll();
}
}
また、この実装は各メソッドの宣言とは異なりますか
public static synchronized read_start()
例えば?
ありがとう