Synchronize on threads on wait/notify
[kaka/cakelight.git] / src / kaka / cakelight / mode / VideoMode.java
index c7985e3..41b599a 100644 (file)
@@ -36,7 +36,9 @@ public class VideoMode extends Mode {
     @Override
     public void resume() {
         isPaused = false;
-        grabberThread.notify();
+       synchronized (grabberThread) {
+           grabberThread.notify();
+       }
     }
 
     @Override
@@ -53,7 +55,9 @@ public class VideoMode extends Mode {
                     while (!isInterrupted()) {
                         Optional<VideoFrame> frame = grabber.grabFrame();
                         if (isPaused) {
-                            wait();
+                           synchronized (grabberThread) {
+                               wait();
+                           }
                         }
                         if (frameConsumer != null) frame.ifPresent(frameConsumer);
                         frame.ifPresent(VideoMode.this::onVideoFrame);