比特币源码研读(4)-main函数(3)

in btc •  7 years ago 

AppInit()函数

App初始化函数

1.png

1)boost::thread_groupthreadGroup

在AppInit函数中,需要声明线程组变量的时候,可以调用这个空间的类来定义,即

             boost::thread_group threadGroup;

注:Thread_group是线程组的意思,可以实现多个线程统一管理。

关于线程组可参考

          http://blog.sina.com.cn/s/blog_788c13b00100v7ma.html
          http://www.jianshu.com/p/0b2e360243f4
          http://zh.highscore.de/cpp/boost/multithreading.html

boost是库函数,我们在编译系统是,会先编译boost库

          sudo apt-get install libboost-all-dev       //安装boost标准库(c++)

因此,源码中,可以直接调用boost

那为什么还要在init.h中声明一个 class thread_group呢?

2.png

因为init.h中使用了boost::thread,如下图

3.png

但是并没有包含

               #include<boost/thread.hpp>

所以,做了一个前向声明

         namespace boost
        {
              class thread_group; 
        } // namespace boost

这样init.h中就可以识别boost::thread_group了,

而在init.cpp中在包含thread.cpp,实现thread_group

2)Cscheduler scheduler

类Cscheduler,定义在src/Scheduler.h,实现在src/Scheduler.cpp

该类的目的是:管理周期运行或临时运行的任务

区块链研习社比特币源码研读班 electroman

以下是广告

我们区块链研习社已创建“区块链研习社币圈交流”小密圈”,在小密圈中,我们将带领大家一起学习区块链的原理与投资,还将提供区块链基本原理解答、交易所注册与交易操作、ICO交易与操作、投资分析、风险分析等内容。

区块链研习社币圈交流.png

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @electroman! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Comment

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!