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通用权限框架B/S (三)--MODEL层(2)
接上篇 实体数据模型保存后生成上下文和实体 上下文和实体实际是由根据.tt模版生成的 当实体数据模型.edmx更新保存后,上下文和实体就会根据.tt模版自动更新 生成的上下文继承 DbContext ...
- 《Oracle Applications DBA 基础》- 9 - Concurrent Processing[Z]
<Oracle Applications DBA 基础>- 9 - Concurrent Processing================================== 参考资料 ...
- windows如何获取Win10 Win8 Win8.1版本
GetVersionEx 在win8 win8.1 win10 之后已经无法使用,如果非要使用的话需要让exe嵌入manifest,mainfest如下.这个文件需要已utf-8存储. <?xm ...
- C语言中头文件<stdio.h>中的#ifndef _STDIO_H_
先了解这里的相关知识:http://www.cnblogs.com/stemon/p/4000468.html 头文件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都in ...
- Linux学习之停止进程
首先,用ps查看进程,方法如下: ps -ef ……smx 1822 1 0 11:38 ? 00:00:49 gnome-terminalsmx 18 ...
- wdcp升级php和mysql
安装没什么好说的,按照wdcp官方去搞就行了,这里如果是centos系统建议使用rpm安装方式附件如下(这里包含了本文后面用到的三个文件) http://download.csdn.net/detai ...
- [置顶] 蓝牙基础知识进阶——Physical channel
从本篇文章开始,晓东将会和大家一起来学习一些蓝牙的比较高阶的基础知识. 二.物理通道 物理通道是piconet区分的标准,它是蓝牙系统结构层次中的最底层了. Q1:物理通道有哪些类型 物理通道 ...
- jquery中validate插件表单验证
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- HTML前端技术(JS的使用,包括数组和字符串)
<script type="text/javascript"> /* JS 数组的操作 //concat 连接两个或更多的数组,并返回结果. var arr1 = ne ...
- HTML5 canvas易错点
一.画布的默认宽高 <canvas id="myCanvas" style="border:1px solid black;"> 你的浏览器不支持h ...