dimanche 30 juillet 2017

Why c++11 thread crash?

Look the code:

#include <iostream>
#include <thread>

using namespace std;

void task(int index){
    cout<<index<<endl;
}

int main()
{
    thread t1(task,1);
    thread t2(task,2);
    t1.join();
    t2.join();
    return 0;
}

The most time, the program runs normally, but sometimes it crashs? Why does it crash?

Aucun commentaire:

Enregistrer un commentaire