mardi 24 avril 2018

C++ - thread_local vector causes crash on join() on MinGW

#include <thread>
#include <vector>
using namespace std;

thread_local vector<int> v;

void foo(int n) 
{  
    for(int i=0 ; i<n ; i++)
        v.push_back(i);
}

int main() 
{
    vector<thread> thread_array;
    for(int i=0 ; i<4 ; i++)
        thread_array.push_back(thread(foo,100));
    for(int i=0 ; i<4 ; i++)
        thread_array.at(i).join();
    return 0;
}

This program crashes for me after reaching the second for loop (the joining one), but not always. Sometimes it exits just fine, sometimes it crashes. What could be causing this? I can post compiler/minGW version details or anything that's needed.

Aucun commentaire:

Enregistrer un commentaire