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:

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 thread
Use: Qt 5.3 win MinGW 4.8 ×32 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
Qt Code:
  1. #ifndef CANNIBALS_H
  2. #define CANNIBALS_H
  3. #include <thread>
  4. #include <mutex>
  5. #include <time.h>
  6. #include <windows.h>
  7. #define M 100
  8.  
  9. #include <QObject>
  10.  
  11. class Cannibals : public QObject
  12. {
  13. Q_OBJECT
  14. public:
  15. explicit Cannibals(QObject *parent = 0);
  16. void Dinner_a(int);
  17.  
  18. private:
  19. void Cooking();
  20. void Dinner();
  21. std::thread Cook;
  22. std::mutex eating;
  23. int food=10;
  24.  
  25. signals:
  26. void NumberChanged(int);
  27.  
  28. public slots:
  29.  
  30. };
  31.  
  32. #endif // CANNIBALS_H
To copy to clipboard, switch view to plain text mode 
cannibals.cpp
Qt Code:
  1. #include "cannibals.h"
  2.  
  3. Cannibals::Cannibals(QObject *parent) :
  4. QObject(parent)
  5. {
  6. }
  7.  
  8. void Cannibals::Cooking()
  9. {
  10. food=M;
  11. }
  12.  
  13. void Cannibals::Dinner_a(int z)
  14. {
  15. eating.lock();
  16. for(int i=0; i<z;i++){
  17. Dinner();}
  18. eating.unlock();
  19. }
  20.  
  21. void Cannibals::Dinner()
  22. {
  23. if(food!=0){
  24. emit NumberChanged(food);
  25. --food;}
  26. else
  27. Cook = std::thread(&Cannibals::Cooking, this);
  28. Cook.join();
  29.  
  30. Sleep(rand() 00);
  31. }
To copy to clipboard, switch view to plain text mode 
mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include "cannibals.h"
  4. #include <ui_mainwindow.h>
  5. #include <QMainWindow>
  6. #include <thread>
  7. #define N 20
  8. #define M 100
  9. #define P (M/N)
  10.  
  11. namespace Ui {
  12. class MainWindow;}
  13.  
  14. class MainWindow : public QMainWindow
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. explicit MainWindow(QWidget *parent = 0);
  20. ~MainWindow();
  21. Cannibals *Foo;
  22. std::thread Cannibal[N];
  23.  
  24. private slots:
  25. void on_pushButton_clicked();
  26.  
  27. private:
  28. Ui::MainWindow *ui;
  29.  
  30. public slots:
  31. void OnNumberChanged (int);
  32. };
  33.  
  34. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 
mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. Foo = new Cannibals();
  10. connect(Foo,SIGNAL(NumberChanged(int)),this,SLOT(OnNumberChanged(int)));
  11. }
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void MainWindow::on_pushButton_clicked()
  19. {
  20.  
  21. for(int i=0;i<N;i++)
  22. {
  23. Cannibal[i] = std::thread(&Cannibals::Dinner_a, Foo, P);
  24. }
  25.  
  26. for(int i=0;i<N;i++)
  27. {
  28. Cannibal[i].join();
  29. }
  30. }
  31.  
  32. void MainWindow::OnNumberChanged(int Num)
  33. {
  34. ui->listWidget->clear();
  35. ui->pushButton->setEnabled(false);
  36. ui->listWidget->addItem(QString(Num) + " cannibal ate");
  37. }
To copy to clipboard, switch view to plain text mode