0
std::mutex task_lock;
    std::mutex running_tasks_lock;
    std::vector<std::string> path;
    std::vector<std::thread *> vecOfThreads;
void __get_fileTree(std::thread *thread)
{
    qDebug() << "YES";
}

void MapSorter::get_fileTree()
{
    task_lock.lock();
    path.push_back("D:\\ymir work\\");
    task_lock.unlock();
    vecOfThreads.clear();

    for (int i = 0; i < 4; i++)
    {
        vecOfThreads.push_back(new std::thread(__get_fileTree, this));
    }

    bool tasks_done_ticker = 4;

    while (tasks_done_ticker > 0) 
    {
        Sleep(10);

        running_tasks_lock.lock();
        task_lock.lock();
        if (path.empty())
        {
            tasks_done_ticker -= 1;
        }
        else 
        {
            tasks_done_ticker = 4;
        }
        running_tasks_lock.unlock();
        task_lock.unlock();
    }

    for (std::thread *s : vecOfThreads)
    {
        s->join();
    }
}

I tryed to create 4 threads and just print a debug to test it. I get this compiler issue so i thought I may have done something wrong but after trying to change the function call several times i couldnt fix it. Any suggestions?

ERROR MESSAGES: Error messages

Changes to

vecOfThreads.push_back(new std::thread(&MapSorter::Repeatget_fileTree, this));

doesnt fix the issue

x3Syntax
  • 11
  • 2

2 Answers2

0

I believe like this

void get_fileTree()
{
    qDebug() << "YES";
}

vecOfThreads.push_back(new std::thread(get_fileTree));

or like this

void get_fileTree(MapSorter *sorter)
{
    qDebug() << "YES";
}

vecOfThreads.push_back(new std::thread(get_fileTree, this));

Sorry about the earlier answer. When I saw this in the arguments to std::thread I assumed wrongly that get_fileTree was a member function.

john
  • 85,011
  • 4
  • 57
  • 81
0
void MapSorter::Repeatget_fileTree()
{
    qDebug() << "YES";
}

and

vecOfThreads.push_back(new std::thread(&MapSorter::Repeatget_fileTree, this));

fixed it. Thanks.

x3Syntax
  • 11
  • 2