64,637
社区成员
发帖
与我相关
我的任务
分享
vector<thread> th;
for (int i = 0; i < 20; i++) {
th.push_back(thread(&SyncList<int>::push_front, &list, ref(numbers[i])));
}
for (auto& t : th) {
t.join();
}
vector<thread> th;
for (int i = 0; i < 20; i++) {
th.push_back(thread([&]() {
list.push_front(numbers[i]);
}));
}
for (auto& t : th) {
t.join();
}
template <class T>
void SyncList<T>::push_front(const T& value)
{
lock_guard<mutex> lck(mtx);
cout << "Push front " << value << endl;
vec.insert(vec.begin(), value);
cond.notify_one();
}