上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 39 下一页
摘要: 官方的解释 “Cronet is the networking stack of Chromium put into a library for use on mobile. This is the same networking stack that is used in the Chrome b 阅读全文
posted @ 2022-06-24 15:31 strive-sun 阅读(2368) 评论(0) 推荐(0)
摘要: 今天在编译项目时,代码审查提示 “Single-parameter constructors should be marked explicit” 于是就在构造函数前加上 explicit 下面为最小的示例,这个示例主要是按文件创建时间排序并删除过期的文件 #include <iostream> # 阅读全文
posted @ 2022-06-22 18:15 strive-sun 阅读(406) 评论(0) 推荐(0)
摘要: 常用的 windbg 命令 .ecxr 用来切换到异常发生时的上下文,主要用在分析静态 dump 文件的时候。当我们使用 .reload 命令去强制加载库的 pdb 文件后,需要执行 .ecxr 命令,重新切换到异常上下文 kn/kv/kp 用来查看当前线程的函数调用堆栈。如果要查看当前进程的所有线 阅读全文
posted @ 2022-06-15 11:19 strive-sun 阅读(1056) 评论(0) 推荐(0)
摘要: 尽量不使用无锁架构,除非绝对必要 复杂性中有一些东西吸引了每一位工程师。与常规同步机制(如互斥锁、条件变量、异步等)相比,无锁编程听起来非常性感。然而,与我交谈过的每一位经验丰富的 C++ 开发人员都认为,使用无锁编程作为首要手段是一种过早的优化形式,可能会在最合适的时候再次困扰你(想想当你没有完整 阅读全文
posted @ 2022-05-31 01:57 strive-sun 阅读(72) 评论(2) 推荐(0)
摘要: 在 C++11 中,不要将 volatile 用于线程,仅限于 MMIO(内存映射) 简单的回答, 在声明变量类型之前添加 "volatile" 关键字不会使对该变量有任何方式的原子操作或者线程安全,我们需要使用 std::atomic 详细的解释, 参考:When to use volatile 阅读全文
posted @ 2022-05-31 01:51 strive-sun 阅读(53) 评论(0) 推荐(0)
摘要: 在 async 任务中抛出的异常会被 std::future::get() 触发 #include <future> #include <iostream> int main() { std::future<int> myFuture = std::async(std::launch::async, 阅读全文
posted @ 2022-05-31 01:43 strive-sun 阅读(77) 评论(0) 推荐(0)
摘要: std::async 在简单的 IO 上比 std::thread 更有优势 前提:如果我们只需要一些异步执行的代码,这样不会阻塞主线程的执行,最好的办法是使用 std::async 来执行这些代码。这些操作我们也可以使用 std::thread 创建线程并通过函数指针 或者 lambda 参数将可 阅读全文
posted @ 2022-05-28 16:04 strive-sun 阅读(165) 评论(0) 推荐(0)
摘要: 不要在对时间敏感的上下文中使用 .get() 先看下面的代码, #include "stdafx.h" #include <future> #include <iostream> int main() { std::future<int> myFuture = std::async(std::lau 阅读全文
posted @ 2022-05-28 15:31 strive-sun 阅读(103) 评论(0) 推荐(0)
摘要: 前提: C++ 11 中提供了多线程的标准库,提供了管理线程、保护共享数据、线程间同步操作、原子操作等类。多线程库对应的头文件是 #include <thread>,类名为 std::thread。 然而线程毕竟是比较贴近系统的东西,使用起来仍然不是很方便,特别是线程同步及获取线程运行结果上就更加麻 阅读全文
posted @ 2022-05-28 14:38 strive-sun 阅读(1503) 评论(0) 推荐(0)
摘要: 线程中的异常可以使用 std::rethrow_exception 抛给主线程 问题分析:一个线程中抛出的异常是没法被另一个线程捕获的。假如我们在主线程中创建一个子线程,子线程中的函数抛出了异常,主线程的 catch 是不会触发,如下, #include<iostream> #include<thr 阅读全文
posted @ 2022-05-22 18:37 strive-sun 阅读(569) 评论(0) 推荐(0)
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 39 下一页