C++原子操作中的内存顺序

C++原子操作中的内存顺序 头文件 <atomic> C++11形式 typedef enum memory_order { memory_order_relaxed, memory_order_consume, memory_order_acquire, memory_order_release, memory_order_acq_rel, memory_order_seq_cst } memory_order; C++20形式 enum class memory_order : /*unspecified*/ { relaxed, consume, acquire, release, acq_rel, seq_cst }; inline constexpr memory_order memory_order_relaxed = memory_order::relaxed; inline constexpr memory_order memory_order_consume = memory_order::consume; inline constexpr memory_order memory_order_acquire = memory_order::acquire; inline constexpr memory_order memory_order_release = memory_order::release; inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel; inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst; std::memory_order指定了怎样访问内存,包括常规的、非原子的内存访问、如何围绕原子操作排序。在多核系统中如果没有任何约束,当多个线程同时读写一些变量,一个线程可能以一种顺序观察值的改变不同于其他写入这些值的顺序。确实,这个很明显的顺序改变可能存在于在不同的读取线程之间。一些相似的影响甚至可能发生在单处理器系统,由于编译器内存模型允许的转换。 ...

C++并发笔记

C++ Concurrency in Action Managing threads Basic thread std::thread可以使用函数和callable对象创建 code #include <iostream> #include <thread> #include <mutex> using namespace std; mutex print_lock; void hello_func() { lock_guard<mutex> lg{print_lock}; cout << "hello function: " << std::this_thread::get_id() << endl; } class hello_class { public: void operator()() { lock_guard<mutex> lg{print_lock}; cout << "hello callable: " << std::this_thread::get_id() << endl; } }; int main() { std::thread thread_func(hello_func); hello_class c; std::thread thread_class(c); std::thread thread_lambda([] { lock_guard<mutex> lg{print_lock}; cout << "hello lambda: " << std::this_thread::get_id() << endl; }); { lock_guard<mutex> lg{print_lock}; cout << "main: " << std::this_thread::get_id() << endl; } thread_func.join(); thread_class.join(); thread_lambda.join(); return 0; } 使用detach分离线程和当前线程, 使用join等待线程完成, 如果在调用join时线程是非joinable的就会出现异常, 首先要判断是否joinable ...

数字图像处理笔记

2 数字图像基础 简单成像模型 \[ f(x,y)=i(x,y)r(x,y) \] 其中\(i(x,y)\)为入射到被观察场景的光源照射量, \(r(x,y)\)表示被场景中反射的照射量 ...

图像去雾

暗通道先验法 大气散射模型 \[ I(x)=I_{\infty}r(x)e^{-kd(x)}+I_{\infty}(1-e^{-kd(x)}) \] 其中\(r(x)\)为反射率, \(I_{\infty}\)为无穷远处天空辐射强度, \(I_{\infty}r(x)\)为没有任何干扰情况下的图像, 有雾的情况下大气透射率为\(e^{-kd(x)}\), \(k\)为散射系数 ...

Mermaid类图

原文 Class Diagram 类图用于面向对象对于应用结构概念建模, 也用于把具体的模型翻译成程序代码. 类图也可以用于数据建模 mermaid渲染: classDiagram Animal <|-- Duck Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() } 语法 类结构 顶部代表类名称, 中部代表类成员变量, 底部代表类成员函数 ...

设计模式笔记

SOLID Principle Single Responsibility Principle (SRP) 日记例子,一个类只做一件事 Open-Closed Principle (OCP) 根据颜色大小排序, Specification类,为扩展开发,为修改关闭 Liskov Substitution Principle (LSP) 父类定义的方法意义,子类不能相违背,矩形和正方形的set_size() ...

开发中用到的工具集

简介 总结一下开发中用到的工具 编译开发 msvc WSL2 MinGW Cygwin gcc docker gcc镜像 clang 在线编译器:https://godbolt.org/ IDE Neovim(带LSP) CLion PyCharm Visual Studio Code 编辑器 Typora Neovim Visual Studio Code Cursor 程序库管理 conan vcpkg bintray msys2 pnpm 构建工具 autotools CMake Ninja meson pkg-config(查找库) Bug调试 lldb/gdb/cdb x64dbg valgrind address-sanitizer breakpad/crashpad dbghelp sentry NVIDIA Nsight(调试OpenGL) 版本控制 lazygit(git tui) sublime-merge(git gui) git-bash fork(git gui) gitlab gitea git flow git-interactive-rebase-tool(交互式rebase工具) 文件比较 sublime merge git diff 持续集成 gitlab-runner github workflow Travis CI Bug管理 github/gitlab issues 禅道 代码分析 cppcheck clang-tidy 性能优化 perf Visual Studio: Profiler gperftools 数据解析 imHex HxD wireshark netcat 代码整洁 clang-format clang-tidy editorconfig 打包 7zip Inno Setup Advanced Installer NSIS fupx linuxdeployqt launchpad 资源生成 软件 ...

Matlab2020a在最新Linux下安装报错

Matlab2020a在最新Linux下安装报错 使用的是最新的Manjaro系统 错误内容: Unable to launch the MATLABWindow application 执行./bin/glnxa64/MATLABWindow可以得到具体报错的原因 首先是 bin/glnxa64/MATLABWindow: error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory 安装selinux后是 ...

开发笔记

Windows下格式化显示错误码 使用FormatMessage函数 TCHAR *s = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &s, 0, NULL); OutputDebugString(s); 中文环境下打印: 由于目标计算机积极拒绝,无法连接。 参考 https://stackoverflow.com/questions/3400922/how-do-i-retrieve-an-error-string-from-wsagetlasterror > https://docs.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-formatmessage?redirectedfrom=MSDN 多字节API和UNICODE API 采用Windows接口时, 如果使用宏定义的接口, 如OutputDebugString, 就要考虑到传参在多字节API和UNICODE API直间的兼容 ...

Vim技巧

插件安装 采用packer.nvim安装,根据packer.nvim的文档安装插件管理器,然后在克隆仓库到 # Linux git clone --depth 1 https://github.com/wbthomason/packer.nvim\ ~/.local/share/nvim/site/pack/packer/start/packer.nvim git clone http://github.com/helywin/nvim_config.git ~/.config/nvim # Windows(PowerShell) git clone https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\start\packer.nvim" git clone http://github.com/helywin/nvim_config.git "$env:LOCALAPPDATA\Local\nvim" 然后执行:PackerSync就可以开始自动下载插件安装,我的配置:http://github.com/helywin/nvim_config.git ...

康德的大刀读书笔记

康德的大刀 一、对象 物理学研究的是物体概念,不是实体,研究成果为物体概念间的关系。 物自体是独立于人的思维的东西,我们观察物自体得到杂多,杂多要成为命题必须具备形式,纯粹概念和经验概念,纯粹概念是时间空间(直观)和判断(概念)。命题 = 材料 +(形式 = 时间空间 + 概念),物是形式+材料,称为经验概念。 存在一词不能与物自体连用。 独立于思维的东西无法用来做证明或判断。 凡是事实,一定是经验命题。经验命题不一定要正确或者经验有的。 语言 \[ \begin{align} \text{语言} \begin{cases} \text{所有词,词组、句、成语等等的总和} \\\\ \text{产生事实的能力,造句子的能力} \end{cases} \end{align} \] ...

gettext使用

简介 GNU getttext是实现软件国际化的一套多语言工具,运行程序运行时根据不同的语言环境切换不同的程序语言,对应Qt的Linguist 获取库 使用vcpkg一键安装 ...

CMake技巧

判断CMake编译环境 编译类型CMAKE_BUILD_TYPE 可取Debug, Release, RelWithDebInfo, MinSizeRel等等预设值 if (CMAKE_BUILD_TYPE MATCHES Debug) #do some thing endif() 系统环境CMAKE_SYSTEM_NAME 代表当前系统的类型, 值有ANDROID, APPLE, IOS, UNIX, WIN32, WINCE, WINDOWS_PHONE等 可以直接对这些值进行条件判断来确定 ...

GitLab维护

升级 到清华大学镜像下载apt包 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/ https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/ubuntu/pool/xenial/main/g/gitlab-ee/ 这个xenial是对应Ubuntu 16.04的 直接sudo apt install ./xxxx.deb,不能暂停服务,否则无法备份然后失败 升级前需要备份 ...

诺基亚7Plus刷机

已解锁 刷机 允许usb调试,输入以下命令进入Download mode adb reboot fastboot 准备好twrp镜像,下载地址 由于使用A/B分区,在当前为A分区的时候刷机会刷到B分区,采用临时引导recovery的方式切换分区和刷机 ...