POCO trouble on mac

Hi,
I’m having an issue with running poco activities on mac. I’m trying to set up an activity with a RWLock. The code looks like this:

The header file:

  
  
/**  
	Defines an object that runs as a POCO activity.  
 */  
#ifndef TESTACTIVITY_H  
#define TESTACTIVITY_H  
  
#include "ofMain.h"  
#include "Poco/Activity.h"  
#include "Poco/RWLock.h"  
#include "ofxOpenCV.h"  
  
class TestActivity{  
public:  
	TestActivity() : activity(this, &TestActivity::runActivity){}  
	void init();  
	void start();  
	void stop();  
	  
protected:  
	void runActivity();  
	  
private:  
	Poco::Activity<TestActivity> activity;  
	Poco::RWLock rwLock;  
};  
  
#endif  
  

and the cpp file:

  
  
/**  
	Implements an object that runs as a POCO activity.  
 */  
  
#include <iostream>  
using std::cout;  
using std::endl;  
  
#include "TestActivity.h"  
  
void TestActivity::init(){  
}  
  
void TestActivity::start(){  
	activity.start();  
}  
  
void TestActivity::stop(){  
	activity.stop();  
}  
  
void TestActivity::runActivity(){  
	while(!activity.isStopped()){  
		if(rwLock.tryReadLock()){  
			cout << "Hello I'm running in an activity..." << endl;  
			ofxCvColorImage pig;  
			pig.allocate(100, 100); //THIS LINE IS THE PROBLEM ON OS X  
			rwLock.unlock();  
		}  
		ofSleepMillis(700);  
	}  
}  
  

the problem lies in the allocate instruction on the ofxCvColorImage. If I outcomment the instruction the activity runs without problems.

Also the allocation works if the whole thing is running in visual studio on windows.

I’m generally new to to threads so wonder if I’m doing something wrong and windows just ignores it, or there is a bug on the mac?

Hope some of you people can help me, I’m running out of places to hit my head :frowning:

greetings,

when you say problem, do you mean, crashing? freezing? don’t see anything?

one problem is that the allocate function of the ofxCvImage has some opengl allocation in it, which might be problematic to do in a thread (opengl is not multithreaded).

if you don’t need to draw the image, or can put the pixels somewhere else to draw, can you try:

  
  
ofxCvColorImage pig;  
pig.setUseTexture(false);  
pig.allocate(100, 100);  
  

take care!
zach

oh sorry that I forgot to mention that.
The program crashes at that line of code.

But yes the thing about OpenGL definitely makes sense, I wasn’t aware of that.

Just tried your tip and it works. Thanks a lot for your help, definitely made my day better :smiley:

But do you have any idea why the original code worked on windows and not on mac?

different implementations of opengl, maybe? on a pc, do you see anything? as I recall, on a pc, opengl stuff fails in other threads but gracefully (no crashes), I guess on a mac it’s different.

there are alot of differences among the platforms especially as it related to error handling, etc. Some of it also compiler related.

glad that helped !
zach

yeah it was running with no problems or warnings what so ever so was just wondering.

But everything runs fine now, thx again for the help.

I once had the same issue moving from a macbook pro to a macmini. It seemed that some opengl features were threadsafe on one computer (opengl implementation) while not on the others. I also believe that mac pros support opengl multithreading. Unless stated otherwise I would assume that multithreading is not supported, though.