Thread issue with while (true)

Use delay() for functions continuously running in another thread():
Processing.org/reference/delay_.html
Processing.org/reference/thread_.html

int play;
color c;

void setup() {
  size(200, 150);
  frameRate(4);
  thread("holo");
}

void draw() {
  play = round(random(1));
  background(c);
  getSurface().setTitle("Frames: " + frameCount);
}

void holo() {
  while (true) {
    if (play == 1)  c = (color) random(#000000);
    delay(1);
  }
}

Alternatively, declare the conditional variable as volatile:

volatile int play;
color c;

void setup() {
  size(200, 150);
  frameRate(4);
  thread("holo");
}

void draw() {
  play = round(random(1));
  background(c);
  getSurface().setTitle("Frames: " + frameCount);
}

void holo() {
  while (true) {
    if (play == 1)  c = (color) random(#000000);
    //delay(1);
  }
}
3 Likes