Is operator overloading necessary when instantiating a threadedObject?

Hi all,

I am trying to implement a threaded version of a class that controls points (particles) on screen.

class threadedParticleSystem : public ofThread
{
    public:
        threadedParticleSystem(){}
        threadedParticleSystem( int _num, ofVec2f _origin, float _width, float _height );
        ~threadedParticleSystem();

//thread functions
void start(){ startThread(true, false); } // blocking, verbose
void stop(){ stopThread(); }
void threadedFunction()
{
while(isThreadRunning() !=0)
{
if ( lock() )
{
updateThread();
unlock();
}
}
}

    //not necessarily threaded functions
    void addParticle();
    void applyForce(ofVec2f f);

    //shared variables
    vector <simpleParticle> particles;
    private:
        void updateThread();
};

There are a number of questions that I have here:

  1. the “threadedFunction()” is a callback function that the poco thread calls?
  2. the member functions addParticle() and applyForce() are run in the thread? or will they be called from the main thread?

I try to instantiate the object above in another class

.h:

threadedParticleSystem ps0;

.cpp:
(in constructor)

ps0 = threadedParticleSystem(0, ofVec2f(400,PROJECTOR_HEIGHT+10), 100, 0) );

if I try to compile this I get the following weird error

In file included from ../../../libs/openFrameworks/types/ofTypes.h:69:0,
                 from ../../../libs/openFrameworks/utils/ofLog.h:5,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/scenes/sceneGeiser/sceneGeiser.h:2,
                 from src/scenes/sceneGeiser/sceneGeiser.cpp:1:
../../../libs/poco/include/Poco/Mutex.h: In member function ‘ofThread& ofThread::operator=(const ofThread&)’:
../../../libs/poco/include/Poco/Mutex.h:171:13: error: ‘Poco::FastMutex& Poco::FastMutex::operator=(const Poco::FastMutex&)’ is private
  FastMutex& operator = (const FastMutex&);

I have not idea what I do wrong and the compile error ended up being thrown at FastMutex assignment operator.

thank you for your help

Hello,

You’re class inherits the method start(), stop() and most importantly the virtual method threadedFunction() from the ofThread class. It is this last one that actually runs in its own thread. In your implementation, you let it run your own private function updateThread(). This function can not be accessed by the ofThread class, since it’s private. Try putting the contents of your updateThread() directly in threadedFunction() or at least make it public.

Your other functions are not run in a separate thread.

Best, V

@Vjacobs Hi there,
unfortunately, this did not solve the problem.
I made the “updateThread()” function public and even copied it inside “threadedFunction()”

the error shows up in compilation again…