Dlib库【4】——定时器Timer,线程对象
来源:互联网 发布:java服务器架构 编辑:程序博客网 时间:2024/06/04 19:13
配置Dlib环境: 链接
Timer可以规律地循环调用特定的功能函数
//可以定时地开启线程(例如过30ms打开第二个线程而不把主线程阻塞住?)
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt/*This is an example illustrating the use of the timer object from the dlib C++ Library.The timer is an object that calls some user specified member function at regularintervals from another thread.*/#include <dlib/timer.h>#include <dlib/misc_api.h> // for dlib::sleep#include <iostream>using namespace dlib;using namespace std;// ----------------------------------------------------------------------------------------class timer_example{public:void action_function(){// print out a message so we can see that this function is being triggeredcout << "action_function() called" << endl;}};// ----------------------------------------------------------------------------------------int main(){//直观上timer的主要作用是可以精确的过一段时间再开第二个线程timer_example e;// Here we construct our timer object. It needs two things. The second argument is// the member function it is going to call at regular intervals and the first argument// is the object instance it will call that member function on.timer<timer_example> t(e, &timer_example::action_function);// Set the timer object to trigger every secondt.set_delay_time(1000);// Start the timer. It will start calling the action function 1 second from this call// to start.t.start();// Sleep for 10 seconds before letting the program end. dlib::sleep(10000);//dlib::sleep(10000);// The timer will destruct itself properly and stop calling the action_function.}// ----------------------------------------------------------------------------------------
2.线程对象
pause可以暂停,直观上没有看出特别重要的作用…………之后如果用到了再来丰润吧
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is an example illustrating the use of the threaded_object
from the dlib C++ Library.
This is a very simple example. It creates a single thread that
just prints messages to the screen.
*/
#include <iostream>#include <dlib/threads.h>#include <dlib/misc_api.h> // for dlib::sleepusing namespace std;using namespace dlib;class my_object : public threaded_object{public:my_object(){// Start our thread going in the thread() functionstart();}~my_object(){// Tell the thread() function to stop. This will cause should_stop() to // return true so the thread knows what to do.stop();// Wait for the thread to stop before letting this object destruct itself.// Also note, you are *required* to wait for the thread to end before // letting this object destruct itself.wait();}private:void thread(){// This is our thread. It will loop until it is told that it should terminate.while (should_stop() == false){cout << "hurray threads!" << endl;dlib::sleep(500);}}};int main(){// Create an instance of our threaded object. my_object t;dlib::sleep(4000);// Tell the threaded object to pause its thread. This causes the// thread to block on its next call to should_stop().t.pause();dlib::sleep(3000);cout << "starting thread back up from paused state" << endl;// Tell the thread to unpause itself. This causes should_stop() to unblock // and to let the thread continue.t.start();dlib::sleep(4000);// Let the program end. When t is destructed it will gracefully terminate your// thread because we have set the destructor up to do so.}
阅读全文
0 0
- Dlib库【4】——定时器Timer,线程对象
- Java线程-Timer定时器
- Timer TimerTask 定时器线程
- Dlib库【3】——Thread线程,数据统计
- 【多线程】——定时器Timer
- JAVASE总结--线程定时器Timer
- 定时器Timer、线程(池)
- timer.schedule —— timer定时器的用法
- timer.schedule —— timer定时器的用法
- Poco库Timer定时器
- 4种定时器 Timer
- 线程同步通信与定时器Timer使用
- .线程同步通信与定时器Timer使用
- java线程系列---类中的定时器Timer
- Timer和TimerTask线程定时器用法
- 讲过多线程封装的定时器Timer
- 线程学习笔记(八)-定时器(Timer)
- 关于线程定时器Timer的启动
- 隐马尔可夫模型 HMM
- 普元 BPS表结构参考
- Caffe使用step by step:caffe框架下的基本操作和分析
- 测试一下
- pitch yaw roll是什么
- Dlib库【4】——定时器Timer,线程对象
- 关于easyPOI导出Excel功能
- Docker 进入启动容器
- Angular Js入门之ng-bind和ng-model和{{}}的区别
- 只使用处理I/O的PrintDigit函数,编写一个过程以输出任意实数
- atlas、panel与z轴、depth的关系
- OpenCV中对Mat里面depth,dims,channels,step,data,elemSize和数据地址计算的理解
- Atom-入门快捷键
- Ubantu修改系统时间(VMWare虚拟机上)