We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, hope someone can shed some light on this. This is my first time working with threads in processing I'm using a simple implementation of thread("somemethod"). Within somemethod() I have a globally declared boolean being altered but this is not being recognised by other functions in the main draw() loop?! simplified code below :)
simplified code shown in the post below.
Any suggestions would be greatly appreciated!
In a nutshell how do you get a variable (boolean) state change in one thread to affect the state of the same boolean in another thread? :)
Answers
Please format your code for the forum.
whoops, lets try that again..
formating fixed by moderator
this is a simplified version of the actual code.. please refer to the question above! thanks
Wouldn't be much easier & safer to simply issue
readyToStream = false;
beforethread("faceDetect");
?You know, draw() is called back @ ~60 FPS. And while faceDetect() is busy executing its task, kinect.getVideoImage() & kinectPointCloud() can happen to be invoked in next draw() frame, while faceDetect() is still delaying
readyToStream = false;
! :-SUnfortunately its not that simple.. The faceDetect method determines if a face is present and sets readyToStream to false and readyToCapture to false.. This happens inside the faceDetect() method.. So somehow I need to synchronize / track the boolean change happening across the other threads.. Hope I'm making sense!
Since the booleans are being set in another thread you can't be sure when it happens in tthe main thread. So in the faceDetect method readyToStream is set false but perhaps not in time for the next frame when it is tested again in lines 10 and 14
while (true) {}
orfor ( ; ; ) {}
.https://forum.Processing.org/two/discussion/10654/getting-video-jitter-from-webcam-capture
Hey thanks everyone for your quick replies!
Turns out the booleans were actually doing their job switching between threads and methods as the code currently stands! .. the "error" was being caused by where i'd placed a copy array statement i made... by passing the boolean..
long story short.. i figured out the problem! :)
but Iam curious.. if you did declare a thread in the setup, i.e. thread"someMethod".. how would you call it in the draw loop if you need the method to run intermittently? someMethod(); ? or while(true){someMethod();} or while(true){thread"someMethod";}
readyToCapture == true
from draw().false
.Hi all, sorry thought I'd ask a related question in here instead of starting a new post :)
So i've got a separate thread running openCV's face detection (running at 12fps-ish) the main animation thread is at 60fps.
The issue is, when I try write out info from the OpenCV thread into the main animation thread and try to use it.
The animation thread drops to 12fps?!.. I know I'm missing some trick here..
some pseudo code to illustrate my point.. (maybe not necessary but just incase)
I guess the question is how can I tell processing to get the current instance of the values instead of waiting for the next 4 frames.
Thanks guys!