Strange behaviour of std::thread in Visual Studio 2012

Today I came across some strange behaviour with the VS2012 implementation of std::thread. The created thread’s job was to access the XIMEA camera API, one method of thread creation worked ok, and another only half worked.

With the first mode the API could grab from multiple cameras as expected, while with the other it could only grab from one camera – grabbing from the second camera would always fail. To make things stranger the mode that worked required the passing of an un-used argument to the thread function!

Here is the mode that didn’t work:

int t_func() {
	return do_stuff();
}
void start_thread() {
	std::thread t(t_func);
	t.detach();
}

And here is the mode that does work OK, notice the dummy argument that is passed but otherwise unused!

int t_func(void*) {
	return do_stuff();
}
void start_thread() {
	std::thread t(t_func, (void*)NULL);
	t.detach();
}

All very strange!

1 reply
  1. admin
    admin says:

    A further update on this story: After installing update 3 for Visual Studio 2012 I can’t get std::thread() won’t work with the XIMEA library at all.

    _beginthreadex() and CreateThread() bot work but I can’t get std::thread() to work, even though it seems to use _beginthread()…

    Anyway, I will have to dig into this a bit more if I can find the time…

Comments are closed.