samedi 29 octobre 2016

Why does the following C++11 code fails?

The following code (under Visual Studio 2013) fails in the assert. Can someone explain why this happens?

#include <thread>
#include <cassert>

std::thread t;

void threadTask()
{
   assert(t.get_id() == std::this_thread::get_id());
}

int main()
{
    for (int i = 0; i < 1000; ++i)
    {
        t = std::thread(threadTask);
        t.join();
    }
}

I'm looking for a way to check that a function is called from a specified thread...

Aucun commentaire:

Enregistrer un commentaire