Sanitizers/data_race/data_race_case.cpp (17 lines of code) (raw):
#include <pthread.h>
#include <stdio.h>
#include <string>
#include <map>
typedef std::map<std::string, std::string> map_t;
void *threadfunc(void *p) {
map_t &m = *(map_t *) p;
m["foo"] = "bar";
return 0;
}
int main() {
map_t m;
pthread_t t;
pthread_create(&t, 0, threadfunc, &m);
printf("String: foo=%s\n", m["foo"].c_str());
pthread_join(t, 0);
}