This is my function:
void cmdChangeSett(cmdbuf* cmd_buffer, CTimeTag tagger, uint8_t chNum, int mask) {
double* oldChannelvoltage = new double[chNum];
double* newChannelvoltage = new double[chNum];
bool* oldEdge = new bool[chNum];
bool* newEdge = new bool[chNum];
int newmask;
double chDiff;
int edgeDiff;
int i;
while (runAcquisition) {
for (i = 0; i < chNum; i++) {
cmd_getThresh_getEdge(cmd_buffer, i, oldChannelvoltage, oldEdge);
}
Sleep(500);
newmask = 0;
for (i = 0; i < chNum; i++) {
cmd_getThresh_getEdge(cmd_buffer, i, newChannelvoltage, newEdge);
chDiff = oldChannelvoltage[i] - newChannelvoltage[i];
edgeDiff = oldEdge[i] - newEdge[i];
//printf("\nOld: %.2f, New: %.2f -> DIFF = %.2f", oldChannelvoltage[i], newChannelvoltage[i], diff);
if (chDiff != 0) {
WARN(newChannelvoltage[i] > 1.5, newChannelvoltage[i] = 1.5f, "Threshold of %.2fV exceeds channel %i's max. Rounding to %.2fV.", newChannelvoltage[i], i + 1, 1.5);
WARN(newChannelvoltage[i] < -1.5, newChannelvoltage[i] = -1.5f, "Threshold of %.2fV exceeds channel %i's max. Rounding to %.2fV.", newChannelvoltage[i], i + 1, -1.5);
tagger.SetInputThreshold(i + 1, newChannelvoltage[i]);
}
if (edgeDiff) {
if (!newEdge[i]) newmask += 1 << i;
}
}
if (newmask != mask) {
tagger.SetInversionMask(newmask);
mask = newmask;
}
}
delete[] oldChannelvoltage;
delete[] newChannelvoltage;
delete[] oldEdge;
delete[] newEdge;
}
When I launch the thread from the main() it crashes:
int main(int argc, char** argv) {
int mask = 0;
cmdbuf* cmd_buffer;
CTimeTag tagger;
//some code ....
//......
boost::function<void()> cmdChangeSettThread = boost::bind(&cmdChangeSett,cmd_buffer, tagger, 16, mask);
boost::thread th(cmdChangeSettThread);
//some other code ...
return 0;
}
Any idea ?? I thought the problem was caused by the arrays I'm using in the function but I can't figure out how to solve the problem. Thank you very much!