vendredi 27 avril 2018

Running functions from a vector of futures

I'm instantiating a class that can hold futures so I can run these functions according to a scheduler later on. When I try to run my begin() method, my functions are not called.

    class ThreadManager {
public:
    std::vector<std::future<int>>* threadList;
    std::vector<std::promise<int>>* promiseList;

    ThreadManager() {
        threadList = new std::vector<std::future<int>>();
        promiseList = new std::vector<std::promise<int>>();
    }

    ~ThreadManager() {
        delete threadList;
        delete promiseList;
    }

    std::vector<std::future<int>>* getThreadList() {
        return ThreadManager::threadList;
    }

    void addFuture(std::future<int>* x) {
        getThreadList()->push_back(std::move(*x));
    }

    void begin() {
        std::vector<std::future<int>>* futureList = getThreadList();
        int i = 0;
        for (auto iterator = futureList->begin(); iterator != futureList->end(); iterator++) {
            std::cout << "There are " << i + 1 << " items in this list\n";
            std::cout << "Future at " << i << " is " << typeid(futureList->at(i)).name() << std::endl;
            futureList->at(i).get();
            i++;
        }
    }

};

My main instantiates a ThreadManager class and adds futures. Why aren't my functions running?

Aucun commentaire:

Enregistrer un commentaire