随笔分类 - C++
摘要:8. C++11新特性又哪些 自动类型推导auto,智能指指针(share_ptr,unique_ptr等),for循环简化,线程相关的(std::thread/std::mutex),空指针nullptr,lambda表达式,等等 9. share_ptr是线程安全的吗 share_ptr里包含引
阅读全文
摘要:std::condition_variable 条件变量std::condition_variable有wait和notify接口用于线程间的同步。如下图所示,Thread 2阻塞在wait接口,Thread 1通过notify接口通知Thread 2继续执行。 具体参见示例代码: #include
阅读全文
摘要:1. new和malloc什么区别? new和malloc都用于在堆上分配内存,new是c++中的关键字,分配内存后还会调用构造函数 2. std中unorded_map,map,multimap有什么区别? unorderd_map中元素不按键值排序,底层数据结构是哈希表,相对map查询速度快,内
阅读全文
摘要:问题 #include<iostream> #include<thread> int main() { int sum = 0; auto f = [&sum]() { for (int i = 0; i < 10000; i++) sum += 1; }; std::thread t1(f); s
阅读全文