Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

The Producer-Consumer Problem - Part IV

Running the following program will result into a race condition:

// { autofold
class Shared {
static final int MAX_BUFFER_SIZE = 3;
static Queue<String> buffer = new ArrayDeque<>();
private static volatile boolean shouldWait = true;
static void waitUntilNotified() {
while (shouldWait);
shouldWait = true;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content