Last active
August 29, 2015 14:22
-
-
Save jmorrill/46783a2968bd2f64058d to your computer and use it in GitHub Desktop.
vs2013 vc++ bug?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////VS 2013 ///// | |
////////////////// | |
#include "stdafx.h" | |
#include <assert.h> | |
#include <thread> | |
#define __thread_local __declspec(thread) | |
const int some_int = 5; | |
struct _thread_local_data | |
{ | |
std::thread::id thread_id; | |
int int_val; | |
void initialize() | |
{ | |
thread_id = std::this_thread::get_id(); | |
int_val = some_int; | |
} | |
}; | |
__thread_local _thread_local_data data; | |
static int static_initialize() | |
{ | |
data.initialize(); | |
return 0; | |
} | |
static int val = static_initialize(); | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
auto this_id = std::this_thread::get_id(); | |
auto x = data.int_val; | |
assert(x == some_int); | |
//assert fails here | |
assert(this_id == data.thread_id); | |
return 0; | |
} | |
mstrobel
commented
Jun 11, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment