// This example is from the book _Java Threads_ by Scott Oaks and Henry Wong.
// Written by Scott Oaks and Henry Wong.
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
// Sample ShareMemory -- Chapter 5, p. 89.
public class ShareMemory extends BusyFlag {
byte memory[];
public ShareMemory (int size) {
memory = new byte[size];
}
public synchronized byte[] attach() {
getBusyFlag();
return memory;
}
public synchronized void detach() {
freeBusyFlag();
}
}
|