CPP11 multithreaded programming error? (prompt nullptr)

1. When writing multithreaded programs using CPP11, an error occurred
2. I have asked in the various technology groups I have added, but no one has answered
3. There is only one similar problem with stackoverflow, but cannot solve the
link: from-nodet-to-stdnullptr-t-compiler-error" rel=" nofollow noreferrer "> https://stackoverflow.com/que...
4. The code segment that reported the error:
this is very strange and does not specify what went wrong. The error is located at the last line "}" character of the whole project
, but the error occurs after I have modified part of the logic code. There is no error before. The code that runs normally
is as follows:

< H1 > Code < / H1 >

cPP11 Standard

int jump_while = false;
while (!jump_while) {
    newTree.begin_flag = true;
    //,, 
    newTree.random_chooser();   // 
    cout << "Choosing phase successful" << endl;   // 
    time_consumption += double(1.0 / newTree.get_frenquency());  // 
    std::future <Node*> *result = new std::future <Node*>[newTree.source_node_sent_in_a_round];  //future 
    vector <thread*> thread_container;
    for (int i = 0; i < newTree.source_node_sent_in_a_round; iPP) {
        int random_index = newTree.random_choosed[i];
        packaged_task<Node*(Node*)> *pac = new packaged_task<Node*(Node*)>(&Tree::transmit);
        thread *p = new thread(std::ref(*pac), newTree.vec[random_index]); // , ,  
        thread_container.push_back(p);  //,
        result[i] = (*pac).get_future();  //future,  
        (*p).join();  // 
    }
    newTree.begin_flag = true;
    newTree.my_condition.notify_all(); // 
    for (int i = 0; i < newTree.source_node_sent_in_a_round; iPP) {
        Node* re = result[i].get();  //, 
        if (re != nullptr) {  //, 
                           //,???? 
            jump_while = true;
            die_first = re;
            break;
        }
    }
    for (int i = 0; i < newTree.source_node_sent_in_a_round; iPP) {
        delete thread_container[i]; //
    }
}

add the referenced header file and node class information (available on stackoverflow)

-sharpinclude <vector>
-sharpinclude <iostream>
-sharpinclude <thread>
-sharpinclude <mutex>
-sharpinclude <queue>
-sharpinclude <cmath>
-sharpinclude <sstream>
-sharpinclude <fstream>
-sharpinclude <cstring>  //for memset
-sharpinclude <algorithm>
-sharpinclude <windows.h>
-sharpinclude <future>
-sharpinclude <condition_variable>

using namespace std;

class Node {
public:
    int num;
    double energy;
    double x, y;
    bool visited;
    Node* father;
    vector <Node*> child;
    int child_num;
    Node(int& node_num, double energy, double x, double y) {
        this->visited = false;
        this->num = node_num;
        this->energy = energy;
        this->x = x;
        this->y = y;
        this->father = NULL;
        this->child_num = 0;
        node_numPP;
    }
    ~Node() {}
    Node* remove_child(Node*);
    void add_child(Node*);
};

Tree class information:

class Tree {
public:
    bool begin_flag;
    mutex begin_lock;
    vector <mutex*> my_lock;
    condition_variable my_condition;
    double THRESHOLD;
    int level_num;
    int SINK_ID; //from 0 to n - 1
    Node* root;
    double Eelec;
    double Efs;
    double Emp;
    double k;
    int frequency;
    double initial_energy_for_sink_node;
    double initial_energy_for_average_node;
    vector <Cordinate> c_vec;
    double communication_range;
    int source_node_sent_in_a_round;
    int number_of_each_node_package;
    int num_getter();
    double get_distance(Node* p1, Node* p2);
    bool able_conn(Node* p1, Node* p2, double communication_range);
    double send_energy(Node* p1, Node* p2);
    double receive_energy();
    int get_average_children_num(int l);
    bool verify_conn(Cordinate c1, Cordinate c2);
    Cordinate random_helper();
    Tree();
    ~Tree();
    vector <Node*> vec; //to storage node[i]"s info (vec[i] = node[i]) 
    vector <vector <Node*> > v2d; //to storage node[i]"s able connected node (v2d[i][j] = node v2d[i][j] able to communicate with node[i])
    vector <vector <Node*> > level; //to storage each level"s node (level[i] represents for all nodes in the level[i])
    vector <int> node_in_tree_vec;
    vector <int> random_choosed;
    void random_data_generator();
    Node* buildTree();
    int get_level_num();
    int level_counter(Node* root);
    Node* get_sink();
    void levelizer(Node* root, int count);
    Node* transmit(Node* source);
    void random_chooser();
    int get_frenquency();
    void topDownBalancing();
    void downTopBalancing();
    void levelOrderTraverse();
    void show_residual_energy();
    int get_source_node_sent_in_a_round();
    string name_getter();
};
< H2 > error message (compilation environment visual studio 2015) < / H2 >

(DEV-CPP)

GCC 4.8.1 release(DEV-CPP 5.7.1)
:

I hope to get some advice from the Great God. Thank you!

CPP
Jun.22,2022

the error is here:

packaged_task<Node*(Node*)> *pac = new packaged_task<Node*(Node*)>(&Tree::transmit);
The transmit method of the

Tree class receives Node* and returns Node* , but this is a member function, so the actual type is not Node* (Node*) . The error messages of VS and GCC actually indicate this, and the type passed in is Node* (Tree::*) (Node*) .

another extra sentence:

create a thread to prevent it from being reclaimed by the recycling mechanism, using a pointer

what the hell is this? Where did CPP get the recycling mechanism? You only have new but no delete, and you may face a memory leak. You may also need to consider the life cycle of the object.


your business logic should be to randomly select N nodes from tree, then calculate N nodes in parallel, and then end after getting the result of a node.

  1. transmit compilation error, refer to std::function calling member function

      libq 
    
  2. it's best to use std::unique_ptr or std::shared_ptr , and use as few bare pointers as possible
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e7cccb-906.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e7cccb-906.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?