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库来减少项目中大量 ...
随机推荐
- .net通用权限框架C/S概览
通用权限框架cs部分 先概述一下,cs使用vs2010+sql2008 和bs公用同一个数据库 为使界面好看使用了第三方控件 donetbar和devexpress,正版是要收费的,但是你们都明白的可 ...
- linux查看与设置主机名
1.设置主机名 通过编辑/etc/sysconfig/network文件中的HOSTNAME字段就可以修改主机名.如下所示: [root@zijuan /]# vim /etc/sysc ...
- Java SE基础部分——常用类库之NumberFormat(数字格式化)
数字格式化常用方法:DecimalFormat和NuberFormat. //2016060524 数字格式化学习 //数字格式化 两种方法 一种直接使用NumberFormat,另一种Decimal ...
- Linux学习之chkconfig命令
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...
- Windows 下 Python easy_install 的安装
下载安装python安装工具 下载地址:http://pypi.python.org/pypi/setuptools 可以找到正确的版本进行下载.win7 32位可以下载setuptools-0.6c ...
- Application Loader下载安装和上传IOS app程序
如果您安装了最新版的XCode开发环境.对于在4.2及以上版本,Developer/Applications/Utilities目录中已经有ApplicationLoader程序,无需执行以下单独安装 ...
- 利用JSP编程技术实现一个简单的购物车程序
实验二 JSP编程 一.实验目的1. 掌握JSP指令的使用方法:2. 掌握JSP动作的使用方法:3. 掌握JSP内置对象的使用方法:4. 掌握JavaBean的编程技术及使用方法:5. 掌握JSP ...
- str系列---字符串函数
1. strcat extern char *strcat(char *dest,char *src); 把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'. 返回指 ...
- 诞生于饭桌上的jcSQL语言
相信每个Coder都有心在自己求学阶段可以写一门自己的语言,无论是毕业设计,还是课余爱好:不管是为了提升B格,还是想练手,抑或对其他语言不满,想自己撸一个,只要坚持下去了,都是不错的理由. 现在正值暑 ...
- SQL Server MySQL 中的 in 与 null
例子: create table t(x int,y int); insert into t(x,y) values(1,1),(2,2),(null,null); 查询一: select x,y f ...