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:
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!