当前位置: 首页 > news >正文

Linux——多线程(五)

1.线程池

1.1初期框架

thread.hpp

#include<iostream>
#include <string>
#include <unistd.h>
#include <functional>
#include <pthread.h>namespace ThreadModule
{using func_t = std::function<void()>;class Thread{public:void Excute(){_func();}public:Thread(func_t func, std::string name="none-name"): _func(func), _threadname(name), _stop(true){}static void *threadroutine(void *args) //注意:类成员函数,形参是有this指针的{Thread *self = static_cast<Thread *>(args);self->Excute();return nullptr;}bool Start(){int n = pthread_create(&_tid, nullptr, threadroutine, this);if(!n){_stop = false;return true;}else{return false;}}void Detach(){if(!_stop){pthread_detach(_tid);}}void Join(){if(!_stop){pthread_join(_tid, nullptr);}}std::string name(){return _threadname;}void Stop(){_stop = true;}~Thread() {}private:pthread_t _tid;//线程tidstd::string _threadname;//线程名字func_t _func;//线程所要执行的函数bool _stop;//判断线程是否停止};
}

 ThreadPool.hpp 

#include<vector>
#include<unistd.h>
#include<string>
#include<queue>
#include"Thread.hpp"using namespace ThreadModule;
const int g_thread_num = 3;//默认线程数
// 线程池->一批线程,一批任务,有任务push、有任务pop,本质是: 生产消费模型
template <typename T>
class ThreadPool
{
public:ThreadPool(int threadnum=g_thread_num)//构造函数:_threadnum(threadnum), _waitnum(0), _isrunning(false){pthread_mutex_init(&_mutex,nullptr);//初始化锁pthread_cond_init(&_cond,nullptr);//初始化条件变量}void Print(){while(true){std::cout<<"我是一个线程"<<std::endl;sleep(1);}}void InitThreadPool(){// 指向构建出所有的线程,并不启动for (int num = 0; num < _threadnum; num++){std::string name = "thread-" + std::to_string(num + 1);_threads.emplace_back(Print,name);//线程处理函数是Print,注意这里有问题}_isrunning = true;}void Start()//启动线程池{for(auto &thread:_threads){thread.Start();std::cout<<thread.name()<<"线程:启动成功"<<std::endl;}}void Wait(){for(auto &thread:_threads){thread.Join();}}// bool Enqueue(const T &t)// {// }~ThreadPool()//析构{pthread_mutex_destroy(&_mutex);pthread_cond_destroy(&_cond);}
private:int _threadnum;//线程的数量std::vector<Thread> _threads;//用vector来存线程std::queue<T> _task_queue;//任务队列pthread_mutex_t _mutex;//锁pthread_cond_t _cond;//条件变量int _waitnum;//有几个线程阻塞bool _isrunning;//判断线程池是否在运行
};

main.cc

#include <iostream>	
#include <string>
#include <memory>
#include "threadpool.hpp"	int main()
{std::unique_ptr<ThreadPool<int>> tp(new ThreadPool<int>()); tp->InitThreadPool();tp->Start();sleep(5);tp->Wait();return 0;
}

 

 此时会报错:无效使用非静态成员函数...

主要原因是成员函数包含this指针而thread.hpp中线程所要执行函数的参数为空:using func_t = std::function<void()>;,导致参数类型不匹配

有两种解决方法

 方法一:在Print函数前面加上static

    static void Print(){while(true){std::cout<<"我是一个线程"<<std::endl;sleep(1);}}

 

方法二:在初始化线程池时用bind绑定ThreadPool内部的Print方法,缺省地设置参数this,就是将this参数默认的绑定到Print方法上,这样一来就和thread.hpp中的参数匹配上了 

    void InitThreadPool(){// 指向构建出所有的线程,并不启动for (int num = 0; num < _threadnum; num++){std::string name = "thread-" + std::to_string(num + 1);//_threads.emplace_back(Print,name);//线程处理函数是Print_threads.emplace_back(std::bind(&ThreadPool::Print,this),name);}_isrunning = true;}

  也是成功运行

就算后面我们需要更改线程的参数
 那么也可以在初始化函数那里固定式的绑定参数了

不需要再去单独给线程设计参数对象了 

一个类的成员方法设计成另一个类的回调方法,常见的实现就是这种

类的成员方法也可以成为另一个类的回调方法,方便我们继续类级别的互相调用

 

1.2代码完善

 

接下来就是如何入队列以及我们的新线程应该做什么任务...

处理任务:每一个线程进来的时候都需要去任务队列中获取任务,所以我们首当其冲的就要对任务队列给它锁住

任务队列的加锁、解锁以及线程的等待与唤醒(条件变量)

private:void LockQueue(){pthread_mutex_lock(&_mutex);}void UnlockQueue(){pthread_mutex_unlock(&_mutex);}void ThreadSleep(){pthread_cond_wait(&_cond, &_mutex);}void ThreadWakeup(){pthread_cond_signal(&_cond);}void ThreadWakeupAll(){pthread_cond_broadcast(&_cond);}

 处理任务

    void HandlerTask(std::string name)//线程处理任务{while (true){//加锁LockQueue();//任务队列中不一定有数据,如果任务队列为空且线程池在跑,那么就阻塞住while(_task_queue.empty()&&_isrunning){_waitnum++;ThreadSleep();_waitnum--;}//如果任务队列是空的,然后线程池又退出了,那么就没必要运行了if(_task_queue.empty() && !_isrunning){UnlockQueue();std::cout<<name<<"quit..."<<std::endl;sleep(1);break;}//不论线程池有没有退出,走到这说明一定有任务 ->处理任务T t = _task_queue.front();_task_queue.pop();UnlockQueue();//解锁t();}}

 注意:这个任务是属于线程独占的任务,不能再任务队列的加锁、解锁之间处理

 入任务队列

如果线程阻塞等待的数量大于0,就唤醒一个线程

 

    bool Enqueue(const T &t){bool ret = false;LockQueue();if(_isrunning){_task_queue.push(t);if(_waitnum>0){ThreadWakeup();}ret = true;}UnlockQueue();return ret;}

threadpool.hpp

任务还没写,所以t()先注释掉

#include<iostream>
#include<vector>
#include<unistd.h>
#include<string>
#include<queue>
#include"LockGuard.hpp"
#include"Thread.hpp"using namespace ThreadModule;
const int g_thread_num = 3;//默认线程数
// 线程池->一批线程,一批任务,有任务push、有任务pop,本质是: 生产消费模型
template <typename T>
class ThreadPool
{
private:void LockQueue(){pthread_mutex_lock(&_mutex);}void UnlockQueue(){pthread_mutex_unlock(&_mutex);}void ThreadSleep(){pthread_cond_wait(&_cond, &_mutex);}void ThreadWakeup(){pthread_cond_signal(&_cond);}void ThreadWakeupAll(){pthread_cond_broadcast(&_cond);}
public:ThreadPool(int threadnum=g_thread_num)//构造函数:_threadnum(threadnum), _waitnum(0), _isrunning(false){pthread_mutex_init(&_mutex,nullptr);//初始化锁pthread_cond_init(&_cond,nullptr);//初始化条件变量}// static void Print()// {//     while(true)//     {//         std::cout<<"我是一个线程"<<std::endl;//         sleep(1);//     }// }// void Print(std::string name)// {//     while(true)//     {//         std::cout<<"我是一个线程,线程名是"<<name<<std::endl;//         sleep(1);//     }// }void InitThreadPool(){// 指向构建出所有的线程,并不启动for (int num = 0; num < _threadnum; num++){std::string name = "thread-" + std::to_string(num + 1);//_threads.emplace_back(Print,name);//线程处理函数是Print//_threads.emplace_back(std::bind(&ThreadPool::Print,this,std::placeholders::_1),name);_threads.emplace_back(std::bind(&ThreadPool::HandlerTask,this,std::placeholders::_1),name);}_isrunning = true;}void Start()//启动线程池{for(auto &thread:_threads){thread.Start();std::cout<<thread.name()<<"线程:启动成功"<<std::endl;}}void HandlerTask(std::string name)//线程处理任务{while (true){//加锁LockQueue();//任务队列中不一定有数据,如果任务队列为空且线程池在跑,那么就阻塞住while(_task_queue.empty()&&_isrunning){_waitnum++;std::cout<<name<<"线程阻塞中..."<<std::endl;ThreadSleep();_waitnum--;}//如果任务队列是空的,然后线程池又退出了,那么就没必要运行了if(_task_queue.empty() && !_isrunning){UnlockQueue();std::cout<<name<<"quit..."<<std::endl;sleep(1);break;}//不论线程池有没有退出,走到这说明一定有任务 ->处理任务T t = _task_queue.front();_task_queue.pop();UnlockQueue();//解锁//t();}}void Stop(){LockQueue();_isrunning = false;ThreadWakeupAll();UnlockQueue();        }void Wait(){for(auto &thread:_threads){thread.Join();}}bool Enqueue(const T &t){bool ret = false;LockQueue();if(_isrunning){_task_queue.push(t);if(_waitnum>0){ThreadWakeup();}ret = true;}UnlockQueue();return ret;}~ThreadPool()//析构{pthread_mutex_destroy(&_mutex);pthread_cond_destroy(&_cond);}
private:int _threadnum;//线程的数量std::vector<Thread> _threads;//用vector来存线程std::queue<T> _task_queue;//任务队列pthread_mutex_t _mutex;//锁pthread_cond_t _cond;//条件变量int _waitnum;bool _isrunning;//判断线程池是否在运行
};

 main.cc

#include <iostream>	
#include <string>
#include <memory>
#include "Task.hpp"
#include "threadpool.hpp"	int main()
{std::unique_ptr<ThreadPool<int>> tp(new ThreadPool<int>()); tp->InitThreadPool();tp->Start();sleep(2);tp->Stop();tp->Wait();return 0;
}

 

2.加上日志与任务

 LOG.hpp(日志)

#pragma once
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <ctime>
#include <cstdarg>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include"LockGuard.hpp"
bool gIsSave = false;
const std::string logname = "log.txt";// 1. 日志是有等级的
enum Level
{DEBUG = 0,INFO,WARNING,ERROR,FATAL
};
void SaveFile(const std::string &filename, const std::string &message)
{std::ofstream out(filename, std::ios::app);if (!out.is_open()){return;}out << message;out.close();
}
std::string LevelToString(int level)
{switch (level){case DEBUG:return "Debug";case INFO:return "Info";case WARNING:return "Warning";case ERROR:return "Error";case FATAL:return "Fatal";default:return "Unknown";}
}std::string GetTimeString()
{time_t curr_time = time(nullptr);struct tm *format_time = localtime(&curr_time);if (format_time == nullptr)return "None";char time_buffer[1024];snprintf(time_buffer, sizeof(time_buffer), "%d-%d-%d %d:%d:%d",format_time->tm_year + 1900,format_time->tm_mon + 1,format_time->tm_mday,format_time->tm_hour,format_time->tm_min,format_time->tm_sec);return time_buffer;
}pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
// 日志是有格式的
// 日志等级 时间 代码所在的文件名/行数 日志的内容
void LogMessage(std::string filename, int line,bool issave,int level, const char *format, ...)
{std::string levelstr = LevelToString(level);std::string timestr = GetTimeString();pid_t selfid = getpid();char buffer[1024];va_list arg;va_start(arg, format);vsnprintf(buffer, sizeof(buffer), format, arg);va_end(arg);std::string message = "[" + timestr + "]" + "[" + levelstr + "]" +"[" + std::to_string(selfid) + "]" +"[" + filename + "]" + "[" + std::to_string(line) + "] " + buffer + "\n";LockGuard lockguard(&lock);if (!issave){std::cout << message;}else{SaveFile(logname, message);}
}
#define LOG(level, format, ...)                                                \do                                                                         \{                                                                          \LogMessage(__FILE__, __LINE__, gIsSave, level, format, ##__VA_ARGS__); \} while (0)

 LockGuard.hpp

#ifndef __LOCK_GUARD_HPP__
#define __LOCK_GUARD_HPP__#include <iostream>
#include <pthread.h>class LockGuard
{
public:LockGuard(pthread_mutex_t *mutex):_mutex(mutex){pthread_mutex_lock(_mutex); // 构造加锁}~LockGuard(){pthread_mutex_unlock(_mutex);}
private:pthread_mutex_t *_mutex;
};#endif

threadpool.hpp

#include<iostream>
#include<vector>
#include<unistd.h>
#include<string>
#include<queue>	
#include"LOG.hpp"
#include"LockGuard.hpp"
#include"Thread.hpp"using namespace ThreadModule;
const int g_thread_num = 3;//默认线程数
// 线程池->一批线程,一批任务,有任务push、有任务pop,本质是: 生产消费模型
template <typename T>
class ThreadPool
{
private:void LockQueue(){pthread_mutex_lock(&_mutex);}void UnlockQueue(){pthread_mutex_unlock(&_mutex);}void ThreadSleep(){pthread_cond_wait(&_cond, &_mutex);}void ThreadWakeup(){pthread_cond_signal(&_cond);}void ThreadWakeupAll(){pthread_cond_broadcast(&_cond);}
public:ThreadPool(int threadnum=g_thread_num)//构造函数:_threadnum(threadnum), _waitnum(0), _isrunning(false){pthread_mutex_init(&_mutex,nullptr);//初始化锁pthread_cond_init(&_cond,nullptr);//初始化条件变量LOG(INFO, "线程池构造成功");}// static void Print()// {//     while(true)//     {//         std::cout<<"我是一个线程"<<std::endl;//         sleep(1);//     }// }// void Print(std::string name)// {//     while(true)//     {//         std::cout<<"我是一个线程,线程名是"<<name<<std::endl;//         sleep(1);//     }// }void InitThreadPool(){// 指向构建出所有的线程,并不启动for (int num = 0; num < _threadnum; num++){std::string name = "thread-" + std::to_string(num + 1);//_threads.emplace_back(Print,name);//线程处理函数是Print//_threads.emplace_back(std::bind(&ThreadPool::Print,this,std::placeholders::_1),name);_threads.emplace_back(std::bind(&ThreadPool::HandlerTask,this,std::placeholders::_1),name);LOG(INFO, "线程 %s 初始化成功", name.c_str());}_isrunning = true;}void Start()//启动线程池{for(auto &thread:_threads){thread.Start();std::cout<<thread.name()<<"线程:启动成功"<<std::endl;}}void HandlerTask(std::string name)//线程处理任务{LOG(INFO, "%s 正在运行...", name.c_str());while (true){//加锁LockQueue();//任务队列中不一定有数据,如果任务队列为空且线程池在跑,那么就阻塞住while(_task_queue.empty()&&_isrunning){_waitnum++;ThreadSleep();_waitnum--;}//如果任务队列是空的,然后线程池又退出了,那么就没必要运行了if(_task_queue.empty() && !_isrunning){UnlockQueue();//std::cout<<name<<"quit..."<<std::endl;sleep(1);break;}//不论线程池有没有退出,走到这说明一定有任务 ->处理任务T t = _task_queue.front();_task_queue.pop();UnlockQueue();//解锁LOG(DEBUG, "%s 获得任务", name.c_str());t();LOG(DEBUG,"%s 处理任务中,结果是%s",name.c_str(), t.ResultToString().c_str());}}void Stop(){LockQueue();_isrunning = false;ThreadWakeupAll();UnlockQueue();        }void Wait(){for(auto &thread:_threads){thread.Join();LOG(INFO, "%s 线程退出...", thread.name().c_str());}}bool Enqueue(const T &t){bool ret = false;LockQueue();if(_isrunning){_task_queue.push(t);if(_waitnum>0){ThreadWakeup();}LOG(DEBUG, "任务入队列成功");ret = true;}UnlockQueue();return ret;}~ThreadPool()//析构{pthread_mutex_destroy(&_mutex);pthread_cond_destroy(&_cond);}
private:int _threadnum;//线程的数量std::vector<Thread> _threads;//用vector来存线程std::queue<T> _task_queue;//任务队列pthread_mutex_t _mutex;//锁pthread_cond_t _cond;//条件变量int _waitnum;bool _isrunning;//判断线程池是否在运行
};

thread.hpp

#include<iostream>
#include <string>
#include <unistd.h>
#include <functional>
#include <pthread.h>namespace ThreadModule
{using func_t = std::function<void(std::string)>;class Thread{public:void Excute(){_func(_threadname);}public:Thread(func_t func, std::string name="none-name"): _func(func), _threadname(name), _stop(true){}static void *threadroutine(void *args) // 类成员函数,形参是有this指针的!!{Thread *self = static_cast<Thread *>(args);self->Excute();return nullptr;}bool Start(){int n = pthread_create(&_tid, nullptr, threadroutine, this);if(!n){_stop = false;return true;}else{return false;}}void Detach(){if(!_stop){pthread_detach(_tid);}}void Join(){if(!_stop){pthread_join(_tid, nullptr);}}std::string name(){return _threadname;}void Stop(){_stop = true;}~Thread() {}private:pthread_t _tid;//线程tidstd::string _threadname;//线程名字func_t _func;//线程所要执行的函数bool _stop;//判断线程是否停止};
}

 

 main.cc

#include <iostream>	
#include <string>
#include <memory>
#include "LOG.hpp"
#include "threadpool.hpp"	
#include "Task.hpp"	
#include<ctime>int main()
{srand(time(nullptr) ^ getpid() ^ pthread_self());std::unique_ptr<ThreadPool<Task>> tp(new ThreadPool<Task>(5)); tp->InitThreadPool();tp->Start();int tasknum=3;while(tasknum){int a = rand() % 12 + 1;usleep(1000);int b = rand() % 4 + 1;Task t(a, b);LOG(INFO, "主线程推送任务: %s", t.DebugToString().c_str());tp->Enqueue(t);sleep(1);tasknum--;}tp->Stop();tp->Wait();return 0;
}

相关文章:

Linux——多线程(五)

1.线程池 1.1初期框架 thread.hpp #include<iostream> #include <string> #include <unistd.h> #include <functional> #include <pthread.h>namespace ThreadModule {using func_t std::function<void()>;class Thread{public:void E…...

张量分解(4)——SVD奇异值分解

&#x1f345; 写在前面 &#x1f468;‍&#x1f393; 博主介绍&#xff1a;大家好&#xff0c;这里是hyk写算法了吗&#xff0c;一枚致力于学习算法和人工智能领域的小菜鸟。 &#x1f50e;个人主页&#xff1a;主页链接&#xff08;欢迎各位大佬光临指导&#xff09; ⭐️近…...

第三方配件也能适配苹果了,iOS 18与iPadOS 18将支持快速配对

苹果公司以其对用户体验的不懈追求和对创新技术的不断探索而闻名。随着iOS 18和iPadOS 18的发布&#xff0c;苹果再次证明了其在移动操作系统领域的领先地位。 最新系统版本中的一项引人注目的功能&#xff0c;便是对蓝牙和Wi-Fi配件的配对方式进行了重大改进&#xff0c;不仅…...

Docker 部署 Nginx 并在容器内配置申请免费 SSL 证书

文章目录 dockerdocker-compose.yml申请免费 SSL 证书请求头参数带下划线 docker https://hub.docker.com/_/nginx docker pull nginx:1.27注&#xff1a; 国内网络原因无法下载镜像&#xff0c;nginx 镜像文件下载链接 https://pan.baidu.com/s/1O35cPbx6AHWUJL1v5-REzA?pw…...

模型评估与选择

2.1 经验误差与过拟合 错误率&#xff08;error rate&#xff09;&#xff1a; 分类错误的样本数占样本总数的比例 精度&#xff08;accuracy&#xff09;&#xff1a;1- 错误率 训练误差 / 经验误差&#xff1a;在训练集上的误差 泛化误差&#xff1a;在新样本上的误差 过…...

有必要把共享服务器升级到VPS吗?

根据自己的需求来选择是否升级&#xff0c;虚拟专用服务器 (VPS) 是一种托管解决方案&#xff0c;它以低得多的成本提供专用服务器的大部分功能。使用 VPS&#xff0c;您的虚拟服务器将与在其上运行的其他虚拟服务器共享硬件服务器的资源。但是&#xff0c;与传统的共享托管&am…...

LLM代理应用实战:构建Plotly数据可视化代理

如果你尝试过像ChatGPT这样的LLM&#xff0c;就会知道它们几乎可以为任何语言或包生成代码。但是仅仅依靠LLM是有局限的。对于数据可视化的问题我们需要提供一下的内容 描述数据:模型本身并不知道数据集的细节&#xff0c;比如列名和行细节。手动提供这些信息可能很麻烦&#…...

大模型系列3--pytorch dataloader的原理

pytorch dataloader运行原理 1. 背景2. 环境搭建2.1. 安装WSL & vscode2.2. 安装conda & pytorch_gpu环境 & pytorch 2.112.3 命令行验证python环境2.4. vscode启用pytorch_cpu虚拟环境 3. 调试工具3.1. vscode 断点调试3.2. py-spy代码栈探测3.3. gdb attach3.4. …...

SQLServer 如何设置端口

在SQL Server中&#xff0c;可以通过以下步骤设置端口&#xff1a; 打开SQL Server配置管理器。可以在开始菜单中搜索“SQL Server配置管理器”来找到它。 在左侧导航窗格中&#xff0c;展开“SQL Server网络配置”节点。 选择你要配置的实例&#xff0c;如“SQL Server Netw…...

调整网络安全策略以适应不断升级的威胁形势

关键网络安全统计数据和趋势 当今数字时代网络安全的重要性...

(leetcode学习)9. 回文数

给你一个整数 x &#xff0c;如果 x 是一个回文整数&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 回文数 是指正序&#xff08;从左向右&#xff09;和倒序&#xff08;从右向左&#xff09;读都是一样的整数。 例如&#xff0c;121 是回文&#xff0c;而…...

QT VTK 简单测试工程

目录 1 目录结构 2 文件源码 3 运行结果 4 报错及处理 使用编译好的VTK库进行测试 1 目录结构 2 文件源码 Pro文件 QT core guigreaterThan(QT_MAJOR_VERSION, 4): QT widgetsCONFIG c17# You can make your code fail to compile if it uses deprecated APIs. #…...

ES6 Generator函数的异步应用 (八)

ES6 Generator 函数的异步应用主要通过与 Promise 配合使用来实现。这种模式被称为 “thunk” 模式&#xff0c;它允许你编写看起来是同步的异步代码。 特性&#xff1a; 暂停执行&#xff1a;当 Generator 函数遇到 yield 表达式时&#xff0c;它会暂停执行&#xff0c;等待 …...

Navicat:打造高效数据库管理之道

1. 导言 1.1 介绍Navicat Navicat是一款功能强大的数据库管理工具,旨在帮助用户高效地管理多种类型的数据库,包括MySQL、PostgreSQL、Oracle、SQL Server等。通过Navicat,用户可以轻松地进行数据库的创建、编辑、备份、同步和调试等操作,极大地简化了数据库管理的复杂性。…...

Python和C++全球导航卫星系统和机器人姿态触觉感知二分图算法

&#x1f3af;要点 &#x1f3af;马尔可夫随机场网格推理学习 | &#x1f3af;二维伊辛模型四连网格模型推理 | &#x1f3af;统计物理学模型扰动与最大乘积二值反卷积 | &#x1f3af;受限玻尔兹曼机扰动和最大乘积采样 | &#x1f3af;视觉概率生成模型测试图像 &#x1f3…...

Unity 优化合集

1️⃣ 贴图优化 1. Read/Write Enable 这个属性勾选后允许你在运行时读取和写入纹理数据&#xff0c;这对于需要实时生成内容或者需要动态修改纹理的场合非常有用但在大部分情况下这是不必要的。如果打开这个属性&#xff0c;会使运行时贴图大小翻倍&#xff0c;内存中会额外…...

第九届MathorCup高校数学建模挑战赛-A题:基于数据驱动的城市轨道交通网络优化研究

目录 摘 要 一、 问题的提出 二、 基本假设 三、 符号说明 四、 问题分析 4.1 问题 1 的分析 4.2 问题 2 的分析 4.3 问题 3 的分析 4.4 问题 4 的分析 五、 问题 1 的模型建立与求解 5.1 问题分析 5.2 数据处理 5.2.1 数据统计 5.2.2 异常数据处理方法 5.2.3 剔除异常数据值 5…...

Spring webflux基础核心技术

一、 用操作符转换响应式流 1 、 映射响应式流元素 转换序列的最自然方式是将每个元素映射到一个新值。 Flux 和 Mono 给出了 map 操作符&#xff0c;具有 map(Function<T&#xff0c;R>) 签名的方法可用于逐个处理元素。 当操作符将元素的类型从 T 转变为 R 时&#xf…...

关闭Ubuntu烦人的apport

先来看让人绷不住的&#xff08;恼&#xff09; 我查半天apport是啥玩意发现就一错误报告弹窗&#xff0c;十秒钟给我弹一次一天给我内存弹爆了 就算我程序就算真的不停崩溃&#xff0c;也没你这傻比apport杀伤性强啊&#xff1f;&#xff1f;&#xff1f; 原则上是不建议关闭…...

海事无人机解决方案

海事巡察 海事巡察现状 巡查效率低下&#xff0c;存在视野盲区&#xff0c;耗时长&#xff0c;人力成本高。 海事的职能 统一管理水上交通安全和防治船舶污染。 管理通航秩序、通航环境。负责水域的划定和监督管理&#xff0c;维护水 上交通秩序&#xff1b;核定船舶靠泊安…...

Chapter03-Authentication vulnerabilities

文章目录 1. 身份验证简介1.1 What is authentication1.2 difference between authentication and authorization1.3 身份验证机制失效的原因1.4 身份验证机制失效的影响 2. 基于登录功能的漏洞2.1 密码爆破2.2 用户名枚举2.3 有缺陷的暴力破解防护2.3.1 如果用户登录尝试失败次…...

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...

【磁盘】每天掌握一个Linux命令 - iostat

目录 【磁盘】每天掌握一个Linux命令 - iostat工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景 注意事项 【磁盘】每天掌握一个Linux命令 - iostat 工具概述 iostat&#xff08;I/O Statistics&#xff09;是Linux系统下用于监视系统输入输出设备和CPU使…...

【Go】3、Go语言进阶与依赖管理

前言 本系列文章参考自稀土掘金上的 【字节内部课】公开课&#xff0c;做自我学习总结整理。 Go语言并发编程 Go语言原生支持并发编程&#xff0c;它的核心机制是 Goroutine 协程、Channel 通道&#xff0c;并基于CSP&#xff08;Communicating Sequential Processes&#xff0…...

论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(一)

宇树机器人多姿态起立控制强化学习框架论文解析 论文解读&#xff1a;交大&港大&上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架&#xff08;一&#xff09; 论文解读&#xff1a;交大&港大&上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化…...

多模态大语言模型arxiv论文略读(108)

CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文标题&#xff1a;CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文作者&#xff1a;Sayna Ebrahimi, Sercan O. Arik, Tejas Nama, Tomas Pfister ➡️ 研究机构: Google Cloud AI Re…...

【Android】Android 开发 ADB 常用指令

查看当前连接的设备 adb devices 连接设备 adb connect 设备IP 断开已连接的设备 adb disconnect 设备IP 安装应用 adb install 安装包的路径 卸载应用 adb uninstall 应用包名 查看已安装的应用包名 adb shell pm list packages 查看已安装的第三方应用包名 adb shell pm list…...

Chromium 136 编译指南 Windows篇:depot_tools 配置与源码获取(二)

引言 工欲善其事&#xff0c;必先利其器。在完成了 Visual Studio 2022 和 Windows SDK 的安装后&#xff0c;我们即将接触到 Chromium 开发生态中最核心的工具——depot_tools。这个由 Google 精心打造的工具集&#xff0c;就像是连接开发者与 Chromium 庞大代码库的智能桥梁…...

在 Spring Boot 项目里,MYSQL中json类型字段使用

前言&#xff1a; 因为程序特殊需求导致&#xff0c;需要mysql数据库存储json类型数据&#xff0c;因此记录一下使用流程 1.java实体中新增字段 private List<User> users 2.增加mybatis-plus注解 TableField(typeHandler FastjsonTypeHandler.class) private Lis…...

LangFlow技术架构分析

&#x1f527; LangFlow 的可视化技术栈 前端节点编辑器 底层框架&#xff1a;基于 &#xff08;一个现代化的 React 节点绘图库&#xff09; 功能&#xff1a; 拖拽式构建 LangGraph 状态机 实时连线定义节点依赖关系 可视化调试循环和分支逻辑 与 LangGraph 的深…...