// 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的更多相关文章

  1. google base库中的WaitableEvent

    这个类说白了就是对windows event的封装,没有什么特别的,常规做法,等侍另一线程无非就是等侍事件置信waitsingleobject,通知事件无非就是setevent,一看就明白,不就详解, ...

  2. Chromium base库分割字符串SplitString

    前一段时间在工作过程中遇到一个场景需要将http response中的request header中的cookie字段取出并进行解析,但是手头没有解析cookie的工具类,同时cookie的表现就是个 ...

  3. colmap编译过程中出现,无法解析的外部符号错误 “__cdecl google::base::CheckOpMessageBuilder::ForVar1(void)”

    错误提示: >colmap.lib(matching.obj) : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: cl ...

  4. google base 之MessagePumpForUI

    base库中比较有意思就是这个类了,如同很多界面库一样,创建了一个隐藏窗口来处理需要在界面线程处理的消息,大体原理也就是需要执行task的时候发送一个自定义的消息,当窗口接收到task的时候调用保存起 ...

  5. base库插件---拖动

    /** * Created by Administrator on 2014/6/5 0005. Base-drag 基于Base库的拖拽插件 tags为你要拖拽的元素参数, 数组形式传入 */ $( ...

  6. 解决jquery库和base库的冲突

    jquery库引用在base库之前,$的所有权就是base库的:而jquery库引用在base库之前后的话,$的所有权就是jquery库的.解决这种库之间的冲突可用以下方法解决: 情况一,jquery ...

  7. Google 网络库Volley简介

    Volley是什么? 2013 Google I/O 大会发布的Android平台网络通讯库,旨在帮助开发者实现更快速,简单,健壮的网络通讯.支持网络图片的缓存加载功能. 适用场景:数据量不大,但是通 ...

  8. base库

    /* * 跨浏览器基础库=============================================== * */ //浏览器检测 (function () { window.sys = ...

  9. Guava 教程2-深入探索 Google Guava 库

    原文出处: oschina 在这个系列的第一部分里,我简单的介绍了非常优秀的Google collections和Guava类库,并简要的解释了作为Java程序员,如果使用Guava库来减少项目中大量 ...

随机推荐

  1. php技能考试每日一练

    PHP技術者認定 1, [日本語文字のメール送信] (2016年10月31日)以下のコードは桃家タローさん宛てにメールを送るためのものである.コード内の[(1)]に入る正しいものを1つ次の記述の中から ...

  2. Android中API建议的方式实现SQLite数据库的增、删、改、查的操作

    package com.examp.use_SQLite.dao; import java.util.ArrayList; import java.util.List; import android. ...

  3. UINavigationController技巧<一>——修改返回按钮的标题

    UINavigationController 一般push到另一界面后,返回按钮标题便是上一页面的title,但是对于push的第一页或者是上一页面没有title的,返回按钮标题便是默认back,如图 ...

  4. 基于HTML5 Canvas的网页画板实现教程

    HTML5的功能非常强大,尤其是Canvas的应用更加广泛,Canvas画布上面不仅可以绘制任意的图形,而且可以实现多种多样的动画,甚至是一些交互式的应用,比如网页网版.这次我们要来看的就是一款基于H ...

  5. DevExpress]ChartControl 创建Drill-Down样式的Title

    关键代码: /// <summary> /// 创建Drill-Down样式的Title /// </summary> /// <param name="cha ...

  6. Java基础笔记-异常

    Java中的异常机制: Throwable类是 Java 语言中所有错误或异常的超类.主要包括两个子类: Error和Exception. 一般中要处理的异常是Exception. Java中最常见的 ...

  7. JSthis对象

    第一章: this是javascript语言的一个关键字,它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如 function test(){ ; } 随着函数使用场合的不同,this ...

  8. js charts去掉logo

    打开js charts 3的源代码搜索关键字"fs.bg",然后会找到 fs.bg.2v(fX),将这句代码删掉就OK了,可能有的版本会是fs.bg.2u(fX) 欢迎加入群:25 ...

  9. 【转】sun.misc.BASE64Encoder找不到jar包的解决方法

    只需要在project build path中先移除JRE System Library,再添加库JRE System Library,重新编译后就一切正常了.(太神奇了,转自http://blog. ...

  10. RemoveAll 要重写equals方法

    public class User { private String name; private int age; //setter and getter public String getName( ...