一个线程读,一个线程写; 或者两个线程同时写, 会导致进程崩溃。 如果两个线程同时读,不加锁的情况也不会出现问题。 二.示例代码 #include <boost/thread.hpp> #include <vector> using namespace std; using namespace boost; vector<int> g_vec; void test() { int a = 0; for(int i = 0; i< ...
一个线程读,一个线程写; 或者两个线程同时写, 会导致进程崩溃。 如果两个线程同时读,不加锁的情况也不会出现问题。 二.示例代码 #include <boost/thread.hpp> #include <vector> using namespace std; using namespace boost; vector<int> g_vec; void test() { int a = 0; for(int i = 0; i< ...