Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofThread waiting

$
0
0

@dmelladom wrote:

Hi!
I have a class that inherits from ofThread, to put it simply:

class threadClass: public ofThread{
public:
    int pos;
    string link;
    string path;

    int init(int _pos, string l_ink, string _path, int _config);
    void threadedFunction();
    int method1(string _path, string _link,int _id);
    int hmethod2(string _path, int _id);

};

Methods method1 and method2 are used inside threadedFunction(); and those methods use system calls to command line commands that can run in parallel - I have tested that-
Then, I use a vector to store several of them and start them like this. Note that there are arguments passed from the same vector:

vector<videoDownloader*>::iterator it;
    for (int i = 0; i<a;i++){
        threadVector.push_back(new threadClass);
        it = (threadVector.end()-1);
        int sizeV = threadVector.size();
        string link = links[i];
        string p = path;
        (*it)->init(sizeV, link, p, 0);
        // I could have used (*it)->init(threadVector.size(), links[i], path)
       // but since the vectors are the same, I thought the threads may consider it a shared resource and block it...
        (*it)->startThread();
    }

My problem is that the threads, evoenthough they are started as I can see in the XCode debbuger, do not run at the same time. Only one thread -in addition to the main thread- is executed.

I am not having any other problem, but attending to this storing threads in a vector may be a bad idea.
If you have any suggestions, I will be glad to hear them!
Best,
D!

Posts: 9

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles