5 // shared collection object
6 std::vector<int> v = {1, 2, 3, 5, 8, 13};
9 extern int sthread_access_begin(void* addr, const char* objname, const char* file, int line) __attribute__((weak));
10 extern void sthread_access_end(void* addr, const char* objname, const char* file, int line) __attribute__((weak));
13 #define STHREAD_ACCESS(obj) \
14 for (bool first = sthread_access_begin(static_cast<void*>(obj), #obj, __FILE__, __LINE__) || true; first; \
15 sthread_access_end(static_cast<void*>(obj), #obj, __FILE__, __LINE__), first = false)
17 static void thread_code()
19 // Add another integer to the vector
20 STHREAD_ACCESS(&v) v.push_back(21);
25 std::cout << "starting two helpers...\n";
26 std::thread helper1(thread_code);
27 std::thread helper2(thread_code);
29 std::cout << "waiting for helpers to finish..." << std::endl;
33 // Print out the vector
34 std::cout << "v = { ";
36 std::cout << n << ", ";