随笔分类 -  c++

摘要:为了避免单例类在多线程中重复的创建,下面提供了两种解决方法: 1.互斥锁+双重检查 2.std::call_once() 方法一:互斥锁+双重检查 #include <iostream> #include <thread> #include <mutex> #include <list> using 阅读全文
posted @ 2023-06-18 23:19 十一的杂文录 阅读(61) 评论(0) 推荐(0)
摘要:#include <iostream> #include <thread> #include <mutex> #include <list> #include <future> using namespace std; int myThread(int num) { cout << "myThrea 阅读全文
posted @ 2023-06-18 23:14 十一的杂文录 阅读(53) 评论(0) 推荐(0)
摘要:*:如果 std::async 中传递参数 std::lunnch::deferred ,就需要等待调用 get() 或者 wait() 才会执行,并且代码非子线程运行,而是在主线程中执行 #include <iostream> #include <thread> #include <mutex> 阅读全文
posted @ 2023-06-18 23:12 十一的杂文录 阅读(85) 评论(0) 推荐(0)
摘要:condition_variable 、 wait 、 notify_one 、 notify_all *:notify_one:通知(唤醒)一个线程 *:notify_all:通知(唤醒)多个线程 #include <iostream> #include <thread> #include <mu 阅读全文
posted @ 2023-06-18 23:09 十一的杂文录 阅读(118) 评论(0) 推荐(0)
摘要:timed_mutex 、 try_lock_for 、 try_lock_until #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { publ 阅读全文
posted @ 2023-06-18 23:04 十一的杂文录 阅读(93) 评论(0) 推荐(0)
摘要:// *:这里的lock是函数模板,最少传两个互斥量 // 第一种,使用 lock 和 unlock std::mutex m_mutex1; std::mutex m_mutex2; std::lock(m_mutex1, m_mutex2); m_mutex1.unlock(); m_mutex 阅读全文
posted @ 2023-06-18 23:01 十一的杂文录 阅读(33) 评论(0) 推荐(0)
摘要:*:使用 lock_guard 后,就不可以使用 lock() 和 unlock() *:lock_guard 和智能指针一样,会自动解锁 #include <iostream> #include <thread> #include <mutex> #include <list> using nam 阅读全文
posted @ 2023-06-18 22:59 十一的杂文录 阅读(30) 评论(0) 推荐(0)
摘要:mutex 互斥量的作用是保护共享数据 *:有 lock() 就一定要有 unlock() #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { pu 阅读全文
posted @ 2023-06-18 22:57 十一的杂文录 阅读(55) 评论(0) 推荐(0)
摘要:前言: #include <thread> thread.join() // 阻塞 thread.detach() // 非阻塞 thread.joinable() // bool,判断线程是否支持join或者detach 正文: 创建线程有三种方式,分别是:使用函数来创建线程、使用自定义的类来创建 阅读全文
posted @ 2023-06-18 22:52 十一的杂文录 阅读(432) 评论(0) 推荐(0)
摘要:C++ 20 format #include <iostream> #include <string> #include <format> using namespace std; int main() { /** C++20,让字符串拼接变的更简单 * 除了常规的 字符串,数字拼接,还支持宽字符, 阅读全文
posted @ 2023-06-18 22:38 十一的杂文录 阅读(1006) 评论(0) 推荐(0)
摘要:std::chrono::milliseconds stopTime(2000); std::this_thread::sleep_for(stopTime); 阅读全文
posted @ 2023-06-18 22:33 十一的杂文录 阅读(169) 评论(0) 推荐(0)
摘要:背景介绍: 我的程序是启动后,默认就隐藏到托盘中,等待http请求后,显示界面。所以最小化到托盘的代码,我是写在初始化里面。 正文: 一、自定义消息 WM_SHOWTASK #define WM_SHOWTASK (WM_USER + 101) 二、在类向导中添加消息处理 点击【类向导】、【消息】、 阅读全文
posted @ 2023-05-17 13:34 十一的杂文录 阅读(300) 评论(0) 推荐(0)
摘要:背景: 现在公司项目需要做一个检测更新的功能,通过访问后台接口,判断是否需要更新。 后台接口是 https 协议的,接口需要post请求,需要带参数,来判断是哪个软件需要做检测更新的操作。 客户端软件使用Qt写的 重点 & 注意事项: 1.https协议,需要用到 ssl,如果跑起来报错,基本都是 阅读全文
posted @ 2022-10-24 14:50 十一的杂文录 阅读(1353) 评论(0) 推荐(0)
摘要:读文件返回base64函数: void CZZUser::hidFileToBase(const char* filePath) { // 文件 转 base64 // 计算文件长度 unsigned long filesize = 0; FILE* f1; f1 = fopen(filePath, 阅读全文
posted @ 2022-06-17 15:46 十一的杂文录 阅读(359) 评论(0) 推荐(0)
摘要:不得不bb一下, 场景:用户传base64数据,我生成PDF文件保存到指定路径下 背景:在前人写好的工程上增加这个功能,工程中有base64的.h, .cpp 文件,我试了base64编码没有问题,所以在用到解码的时候,我理所当然的认为解码函数也是没问题的,但是每次我写完文件,就发现文件报错损坏打不 阅读全文
posted @ 2022-06-17 15:41 十一的杂文录 阅读(490) 评论(0) 推荐(0)
摘要:# mytest.py class Test: def hello(self): print("this is test class hello function no params return 123") return 123 def myadd(self, x, y): print("this 阅读全文
posted @ 2022-04-02 17:30 十一的杂文录 阅读(219) 评论(0) 推荐(0)
摘要:# mytest.py def myjoin(a, b): print("num a + str b") return f"{a}=={b}" #include "Python.h" #include <iostream> using namespace std; int main(int argc 阅读全文
posted @ 2022-04-02 17:29 十一的杂文录 阅读(236) 评论(0) 推荐(0)
摘要:# mytest.py def myadd(a, b): print("this is test python print add function") return a+b #include "Python.h" #include <iostream> using namespace std; i 阅读全文
posted @ 2022-04-02 17:27 十一的杂文录 阅读(117) 评论(0) 推荐(0)
摘要:# mytest.pydef hello1(): print("this is test python print hello world 1") return "456" #include "Python.h" #include <iostream> using namespace std; in 阅读全文
posted @ 2022-04-02 17:25 十一的杂文录 阅读(609) 评论(0) 推荐(0)
摘要:# mytest.py def hello(): print("this is test python print hello world") return 123 #include "Python.h" #include <iostream> using namespace std; int ma 阅读全文
posted @ 2022-04-02 17:24 十一的杂文录 阅读(173) 评论(0) 推荐(0)