Thunderbrook commented on code in PR #149:
URL: https://github.com/apache/brpc-website/pull/149#discussion_r1209214572
##########
content/zh/docs/blogs/sourcecodes/bthread_schedule/index.md:
##########
@@ -0,0 +1,341 @@
+---
+title: "bRPC源码解析·bthread调度执行流程"
+linkTitle: "bRPC源码解析·bthread调度执行流程"
+weight: 3
+date: 2023-05-23
+---
+(作者简介:KIDGINBROOK,在昆仑芯参与训练框架开发工作)
+
+## 整体流程
+task_group负责对bthread的调度执行,一个task_group对应一个pthread,内部有两个执行队列,分别为_rq和_remote_rq,执行队列中存放着待执行的bthread。task_control为全局单例,内部有多个task_group。
+
+
+### 主要接口
+
+#### TaskControl
+TaskControl是一个单例,下面是初始化的过程,主要逻辑即为创建_concurrency个worker(bthread_worker)线程,每个worker执行worker_thread函数
+```c++
+int TaskControl::init(int concurrency) {
+ _concurrency = concurrency;
+ _workers.resize(_concurrency);
+ for (int i = 0; i < _concurrency; ++i) {
+ const int rc = pthread_create(&_workers[i], NULL, worker_thread, this);
+ ...
+ }
+ ...
+}
+```
+worker_thread的逻辑为通过create_group创建一个TaskGroup
g,添加到TaskControl中,设置tls_task_group为g,tls_task_group为tls变量,因此只有worker线程的tls_task_group为非null,然后执行TaskGroup的run_main_task函数
+```c++
+void* TaskControl::worker_thread(void* arg) {
+ TaskControl* c = static_cast<TaskControl*>(arg);
+ TaskGroup* g = c->create_group();
+ ...
+ tls_task_group = g;
+ c->_nworkers << 1;
+ g->run_main_task();
+ ...
+}
+```
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]