Using a vector in multithreading, an read access violation is thrown.
I guess it may be a memory access related problem, but I don’t know how to solve it.
Below is my code:
doSomeThing.h
#ifndef _DOSOMETHING_H_
#define _DOSOMETHING_H_
#include <vector>
using namespace std;
typedef unsigned long long ULL;
typedef struct _MSG_STRUCT_
{
ULL header : 16;
ULL msg : 40;
ULL time : 40;
ULL body : 16;
ULL tail : 21;
ULL flag : 1;
ULL continuous : 1;
} MSG_STRUCT;
class MSG_CLUSTER
{
public:
vector<MSG_STRUCT> vect;
void msg_show();
};
#endif
doSomeThing.cpp
#include <iostream>
#include <fstream>
#include "doSomeThing.h"
using namespace std;
void MSG_CLUSTER::msg_show()
{
for (;;)
{
if (!(vect.empty()))
{
vector<MSG_STRUCT>::iterator it_begin = vect.begin();
while (it_begin != vect.end())
{
cout << hex << (*it_begin).header << endl;
it_begin++;
vect.erase(it_begin - 1);
}
}
}
};