Invalid parameter passed to C runtime function
-
Hi everybody,
have some trouble with Runtime library on step run of application (compiling was successful, build too) but when I press Start have a crash with this tags:
bq. Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
terminate called after throwing an instance of 'std::system_error'
what(): Invalid argument
QObject::killTimers: timers cannot be stopped from another threadUse: Qt 5.3 win MinGW 4.8 x32 but run on x64 system, maybe problem here but i'm not sure
or because I try to combine c++11 code with Qt, but not sure too, because Qt traslate all it code to C++...cannibals.h
@#ifndef CANNIBALS_H
#define CANNIBALS_H
#include <thread>
#include <mutex>
#include <time.h>
#include <windows.h>
#define M 100#include <QObject>
class Cannibals : public QObject
{
Q_OBJECT
public:
explicit Cannibals(QObject *parent = 0);
void Dinner_a(int);private:
void Cooking();
void Dinner();
std::thread Cook;
std::mutex eating;
int food=10;signals:
void NumberChanged(int);public slots:
};
#endif // CANNIBALS_H@
cannibals.cpp
@#include "cannibals.h"Cannibals::Cannibals(QObject *parent) :
QObject(parent)
{
}void Cannibals::Cooking()
{
food=M;
}void Cannibals::Dinner_a(int z)
{
eating.lock();
for(int i=0; i<z;i++){
Dinner();}
eating.unlock();
}void Cannibals::Dinner()
{
if(food!=0){
emit NumberChanged(food);
--food;}
else
Cook = std::thread(&Cannibals::Cooking, this);
Cook.join();Sleep(rand() 00);
}@
mainwindow.h
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "cannibals.h"
#include <ui_mainwindow.h>
#include <QMainWindow>
#include <thread>
#define N 20
#define M 100
#define P (M/N)namespace Ui {
class MainWindow;}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Cannibals *Foo;
std::thread Cannibal[N];private slots:
void on_pushButton_clicked();private:
Ui::MainWindow *ui;public slots:
void OnNumberChanged (int);
};#endif // MAINWINDOW_H
@mainwindow.cpp
@#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Foo = new Cannibals();
connect(Foo,SIGNAL(NumberChanged(int)),this,SLOT(OnNumberChanged(int)));
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{for(int i=0;i<N;i++) { Cannibal[i] = std::thread(&Cannibals::Dinner_a, Foo, P); } for(int i=0;i<N;i++) { Cannibal[i].join(); }
}
void MainWindow::OnNumberChanged(int Num)
{
ui->listWidget->clear();
ui->pushButton->setEnabled(false);
ui->listWidget->addItem(QString(Num) + " cannibal ate");
}
@