Problem passing an object as argument to thread

Hello all, I’m attempting to run a process in a separate thread using ofxRuiThread and need to pass an object as an argument… which is not working out.

  
	  
if (model.isNewModel() == true ) {  
		int camW = 640;  
		int camH = 480;  
		  
		// I'm using the ofxRuiThread addon  
		// How can I pass "fern.reInitTracker" to this?    
		threads[1].updateThread();  
		  
		// Reinitialize using the new bmp image and points  
		// Doing this freezes the whole program while the   
		// new image is processed,   
		// so I want to put it into a thread. This code works,   
		// the problem happens when I try to   
		// combine updateThread and reIntTracker  
		fern.reInitTracker(model.newModelName(),camW, camH);  
  
		// I would like to do something like this  
		threads[1].updateThread(fern.reInitTracker(model.newModelName(),camW, camH));  
	}  

**The Project
**Using Theo’s ofxFern as a starting point, I added a new class that allows users to add new objects to be tracked. You can take an image from the webcam, select 4 points, and then generate a new classifier. This process takes a few minutes, however, and freezes the program while it’s processing. So, I’m attempting to add it into a thread. To do this, I need to somehow pass fern.reInitTracker() into threads.updateThread()—basically passing an object as an argument…

After searching the forums, I found topics suggesting using Pointers or ofEvent. I was not able to get these methods to work. I’m relatively new to C++, so I’m guessing what I’m attempting is possible and that I just don’t know the proper syntax.

**I’m using the following setup:
**of_preRelease_v0061_osxSL_FAT
ofxRuiThread
ofxFern https://github.com/ofTheo/ofxFern

**Download Project Here
**
http://mattmillerart.com/ofxFernCameraCreate-debug.zip

Thanks in advance for you time,
-Matt

I have used this in a similar manner. I ended up putting an isReady parameter that I check in my app’s update function

basically if the thread[i].isReady, I do stuff.

here-is-my-SimpleThread

and-here-is-the-main-app

@jvcleave, thanks for the great example! I was able to get your code running at about 18FPS while looking for 6 different Haar Cascades. I’ve written other (non-thread) programs that run slower when only looking for 1!

The way you are using isReady makes sense and looking at the code helps make more sense of how to set up threading.


Just to update this thread on the status of my original code… I was trying to call SimpleThread.update() from testapp.update()… this doen’t work! It’s not even in the example provided with ofxRuiThread so I’m not sure why I added it.

I’ll try reworking the code based on your example and post with updates.

Thanks,
-Matt