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, const char* func)
10 __attribute__((weak));
11 extern void sthread_access_end(void* addr, const char* objname, const char* file, int line, const char* func)
12 __attribute__((weak));
15 #define STHREAD_ACCESS(obj) \
16 for (bool first = sthread_access_begin(static_cast<void*>(obj), #obj, __FILE__, __LINE__, __func__) || true; first; \
17 sthread_access_end(static_cast<void*>(obj), #obj, __FILE__, __LINE__, __func__), first = false)
19 static void thread_code()
21 // Add another integer to the vector
22 STHREAD_ACCESS(&v) v.push_back(21);
27 std::cout << "starting two helpers...\n";
28 std::thread helper1(thread_code);
29 std::thread helper2(thread_code);
31 std::cout << "waiting for helpers to finish..." << std::endl;
35 // Print out the vector
36 std::cout << "v = { ";
38 std::cout << n << ", ";