当前位置:网站首页>colmap源码阅读笔记[1] threading.cc
colmap源码阅读笔记[1] threading.cc
2022-06-10 12:28:00 【感天动地大白狗】
共包含三个类:Thread,ThreadPool,JobQueue,它们各自的作用为:
①Thread:用于创建一个具有单一control+单一timer的线程,是colmap中很多主要工作流的父类;
②ThredPool:线程池类;
JobQueue:
Thread
成员函数和成员变量
①一系列成员变量:
bool started_; // 线程是否启动
bool stopped_; // 线程是否停止
bool paused_; // 线程是否暂停
bool pausing_; // 线程是否正处于暂停状态
bool finished_; // 线程是否已经结束
bool setup_;
bool setup_valid_;
以上变量在初始化时被设为false;
std::thread thread_; // 线程
std::mutex mutex_; // 互斥量
std::condition_variable pause_condition_; // 用于暂停的条件变量
std::condition_variable setup_condition_; // 用于设置的条件变量
Timer timer_; // 计时器
std::unordered_map<int, std::list<std::function<void()>>> callbacks_; // callback函数映射表
②线程状态控制函数:
virtual void Start(); // 线程启动函数,等待之前的线程完成,用当前Run函数构建thread,并设置started_标志位
virtual void Stop(); // 线程停止函数?设置stoped_标志位,调用Resume()恢复线程
virtual void Pause(); // 线程暂停函数,设置paused_标志位
virtual void Resume(); // 线程恢复函数,设置paused_标志位,调用notify_all()唤醒阻塞线程
virtual void Wait(); // 等待函数,等待thread_结束(用join()实现)
其他功能函数:
void BlockIfPaused(); // 当paused_被置位时阻塞,直到线程被resume才恢复
bool CheckValidSetup(); // 当paused_被置位时阻塞,直到pause_condition_被resume才恢复
void SignalValidSetup(); // 当前设置有效,取消CheckValidSetup()的阻塞
void SignalInvalidSetup(); // 当前设置无效,取消CheckValidSetup()的阻塞
void AddCallback(const int id, const std::function<void()>& func); // 添加callback函数到callbacks_
void RegisterCallback(const int id); // 注册一个callback函数,只是留一个位置,并没有实际的函数
void Callback(const int id) const; // 调用对应序号的callback函数
④主要运行函数:
virtual void Run() = 0; // 纯虚函数run,在子类中实现,线程的主要功能在此函数内实现
void RunFunc(); // 调用run函数,创建thread时使用
使用
创建thread的子类,以BundleAdjustmentController为例:
class BundleAdjustmentController : public Thread {
public:
BundleAdjustmentController(const OptionManager& options,
Reconstruction* reconstruction);
private:
void Run();
const OptionManager options_;
Reconstruction* reconstruction_;
};
定义了构造函数和纯虚函数Run()的实现,即可完成一个Thread的子类;
具体使用如下:
BundleAdjustmentController ba_controller(options, &reconstruction);
ba_controller.Start();
ba_controller.Wait();
ThredPool
JobQueue
边栏推荐
- lua语法
- Introduction to the library of C language best practices (Part 2)
- Using Joern to process a large number of files and generate PDG is a slow solution
- eseses
- 微信web开发工具使用教程,公司开发web
- 【限时】,干货满满
- 0509-130 Symbol resolution failed for /oracle/app/oracle/12.2.0/db_ 1/lib/libons. So problem handling
- (十 一)const修飾成員函數
- (4) Classes and objects (1)
- Const Modified member function
猜你喜欢

IO file stream repeat read

Ad-pcb schematic diagram learning (1)

Offer has been made, advanced learning

聊聊消息中间件(1),AMQP那些事儿

What if the xshell evaluation period has expired? Follow the steps below to solve the problem!

【限时】,干货满满

Wechat web development tool tutorial, the company develops Web

已拿offer,进阶学习

Web development

(五)类和对象及类的分文件操作(2)
随机推荐
【严选】,真题解析
VS2010 undefined identifier round
SLM4054独立线性锂电池充电器的芯片的学习
Give root password for maintenace (or press Control-D to continue):解决方法
Learning of fm4057s single lithium battery linear charging chip
ZipOutputStream使用
(十 一)const修飾成員函數
Tensorflow2.0 advanced learning - image (11)
(1) Pretreatment summary
JS array to JSON, JSON to array. Array to comma separated string, string to array
已拿offer,进阶学习
js使用iCheck插件监听获取CheckBox的值
2022年浙江省赛
GIMP - 免费开源的图像处理软件,功能强大,被称为 Photoshop 的优秀替代品
VDMA调试总结
Offer has been made, advanced learning
大牛推荐,吊打面试官
(七)深拷贝与浅拷贝
C# 实现气泡窗体
In the era of digital economy, where should retail stores go