google base库之simplethread
// This is the base SimpleThread. You can derive from it and implement the
// virtual Run method, or you can use the DelegateSimpleThread interface.
class BASE_EXPORT SimpleThread : public PlatformThread::Delegate {
public:
class BASE_EXPORT Options {
public:
Options() : stack_size_(0) { }
~Options() { } // We use the standard compiler-supplied copy constructor. // A custom stack size, or 0 for the system default.
void set_stack_size(size_t size) { stack_size_ = size; }
size_t stack_size() const { return stack_size_; }
private:
size_t stack_size_;
}; // Create a SimpleThread. |options| should be used to manage any specific
// configuration involving the thread creation and management.
// Every thread has a name, in the form of |name_prefix|/TID, for example
// "my_thread/321". The thread will not be created until Start() is called.
explicit SimpleThread(const std::string& name_prefix);
SimpleThread(const std::string& name_prefix, const Options& options); virtual ~SimpleThread(); virtual void Start();
virtual void Join(); // Subclasses should override the Run method.
virtual void Run() = 0; // Return the thread name prefix, or "unnamed" if none was supplied.
std::string name_prefix() { return name_prefix_; } // Return the completed name including TID, only valid after Start().
std::string name() { return name_; } // Return the thread id, only valid after Start().
PlatformThreadId tid() { return tid_; } // Return True if Start() has ever been called.
bool HasBeenStarted(); // Return True if Join() has evern been called.
bool HasBeenJoined() { return joined_; } // Overridden from PlatformThread::Delegate:
virtual void ThreadMain() OVERRIDE; // Only set priorities with a careful understanding of the consequences.
// This is meant for very limited use cases.
void SetThreadPriority(ThreadPriority priority) {
PlatformThread::SetThreadPriority(thread_, priority);
} private:
const std::string name_prefix_;
std::string name_;
const Options options_;
PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join!
WaitableEvent event_; // Signaled if Start() was ever called.
PlatformThreadId tid_; // The backing thread's id.
bool joined_; // True if Join has been called.
};
特别说明,由于需要快速学习,所以,我的文章中有些关于记忆的东西。
这个类相对还是比较简单,就是对线程的简单封装,相比boost的thread简直不知简单到哪里去,不过无所谓,简单能办事就可以。
重写run函数实现自己的逻辑
// Subclasses should override the Run method.
virtual void Run() = 0;
值得注意的就是下面这个数据成员
WaitableEvent event_; // Signaled if Start() was ever called.
到是注解中就说得很明白了,必需要start调用了这个event才置信。这个类先不管它吧,后面还在好戏,google的这个框架应当还是挺好用的,必竟是将thread的windows的消息循环接合得比较紧密,后续文章再一一解开。
google base库之simplethread的更多相关文章
- google base库中的WaitableEvent
这个类说白了就是对windows event的封装,没有什么特别的,常规做法,等侍另一线程无非就是等侍事件置信waitsingleobject,通知事件无非就是setevent,一看就明白,不就详解, ...
- Chromium base库分割字符串SplitString
前一段时间在工作过程中遇到一个场景需要将http response中的request header中的cookie字段取出并进行解析,但是手头没有解析cookie的工具类,同时cookie的表现就是个 ...
- colmap编译过程中出现,无法解析的外部符号错误 “__cdecl google::base::CheckOpMessageBuilder::ForVar1(void)”
错误提示: >colmap.lib(matching.obj) : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: cl ...
- google base 之MessagePumpForUI
base库中比较有意思就是这个类了,如同很多界面库一样,创建了一个隐藏窗口来处理需要在界面线程处理的消息,大体原理也就是需要执行task的时候发送一个自定义的消息,当窗口接收到task的时候调用保存起 ...
- base库插件---拖动
/** * Created by Administrator on 2014/6/5 0005. Base-drag 基于Base库的拖拽插件 tags为你要拖拽的元素参数, 数组形式传入 */ $( ...
- 解决jquery库和base库的冲突
jquery库引用在base库之前,$的所有权就是base库的:而jquery库引用在base库之前后的话,$的所有权就是jquery库的.解决这种库之间的冲突可用以下方法解决: 情况一,jquery ...
- Google 网络库Volley简介
Volley是什么? 2013 Google I/O 大会发布的Android平台网络通讯库,旨在帮助开发者实现更快速,简单,健壮的网络通讯.支持网络图片的缓存加载功能. 适用场景:数据量不大,但是通 ...
- base库
/* * 跨浏览器基础库=============================================== * */ //浏览器检测 (function () { window.sys = ...
- Guava 教程2-深入探索 Google Guava 库
原文出处: oschina 在这个系列的第一部分里,我简单的介绍了非常优秀的Google collections和Guava类库,并简要的解释了作为Java程序员,如果使用Guava库来减少项目中大量 ...
随机推荐
- android捕获程序异常退出
今天看到迅雷动漫里面一个CrashHandler 的类,我猜是崩溃处理类.进去一看.果然.顺便学习一下. Android系统的"程序异常退出",给应用的用户体验造成不良影响.为了捕 ...
- cocos2d-x for wp8 设置横竖屏
在主project文件(xxx.cpp , xxx为你的项目名)中, 函数名为void xxx::SetWindow(CoreWindow^ window) 相关代码片例如以下: <pre na ...
- mvp框架
本文在于巩固基础 mvp框架的概念: MVP是MVC模式的另一个变种,MVP即可以应用到WEB项目中, 也可以应用到Winform项目中,它的方便的测试机制为大型复杂的企业级应用带来了福音,MVP模式 ...
- 在.NET下学习Extjs(第三个案例 Array的过滤方法(filter))
Ext.Array.filter(Array array,Function fn,Object scope):Array array是一个数组,fn是过滤函数,scope是作用域,filter返回的是 ...
- C# List<T>中Select List Distinct()去重复
List<ModelJD> data = myDalJD.GetAllDataList(); List<string> list= new List<string> ...
- oFixed() 方法
oFixed() 方法可把 Number 四舍五入为指定小数位数的数字. 在本例中,我们将把数字舍入为仅有一位小数的数字: Show the number 13.37 with one decimal ...
- 使用ajax异步提交表单
虽然这篇文章的标题是提交表单,但是主要的难点在于使用ajax提交文本域的内容, 在工作中的经常会需要ajax跨域的问题,通常的需求使用jsonp就可以得到解决,但是当前项目中有一个图片服务器,客户端需 ...
- Python进阶之返回函数
返回函数 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB"," ...
- Android Studio Module疑问
ERROR: APK path is not specified for module From your existing project, go to 'File' -> 'Project ...
- hdu 2685 I won't tell you this is about number theory 数论
题目链接 根据公式 \[ gcd(a^m-1, a^n-1) = a^{gcd(m, n)}-1 \] 就可以很容易的做出来了. #include <iostream> #include ...