RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
806 stars 235 forks source link

Comment on Region.observing boolean #234

Closed nicolasavenza closed 7 years ago

nicolasavenza commented 7 years ago

Hi Raiman,

I've been using the java api recently and I'm seeing some strange behavior with the observeInBackground(time) method. What I'm seeing is that sometimes the background threads do not stop even if I call stopObserver() on the region that started observing. I think there might be a race condition with the background observer and the value of observing, especially when running multiple background observers. My first thought is that since the boolean 'observing' is being accessed from multiple threads perhaps it would be best to make it an AtomicBoolean?

Thanks for your hard work on this great project!

RaiMan commented 7 years ago

--1. be sure to use the latest nightly build 1.1.1. --2. the mentioned field need not be atomic, since it is a Region object value, that assures that one region can only run one observer at one time.

So as long as you do not try to start an observer for the same region object in different threads, there should not be a problem. To make it robust for such situations, just making the field atomic is not enough. I would have to make the start of an observer thread safe together with appropriate error messages and may be additional options, that define how to react in such situations (e.g. integrate the additional events into the already running observation). ... but this is something for version 2 Thanks for your input anyway.