You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2022/12/07 15:54:47 UTC

[GitHub] [incubator-brpc] jiangdongzi opened a new issue, #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的tid 100次执行的都是一个值,对应的stack这个指针是空

jiangdongzi opened a new issue, #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042

   并且打印的is_main_task都是true,这种是什么情况呢,这是在同一个bthread中执行的?


-- 
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: dev-unsubscribe@brpc.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1342144228

   > 可以在你服务器上执行函数里加个abort,看一下堆栈吗
   
   ![image](https://user-images.githubusercontent.com/17529657/206375911-7434d569-e8e9-407c-80b6-feb5580b6b46.png)
   可以看到调用函数得到的局部变量与gdb打印的真实值不一样,  gdb打印的真实值看起来是正确的


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1343869254

   > > 看起来就是 g->current_task()获取到的值不等于g->_cur_meta 但是代码就是这样写的:
   > > ```c++
   > > TaskMeta* current_task() const { return _cur_meta; }
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > 感觉可能是编译器的bug,你可尝试关闭编译优化,看看问题是否还出现
   > 
   > 我也这么猜测的, 晚点试试看
   
   想到一个问题,你是否没有在头文件中定义NDEBUG宏?
   如果有的代码有这个宏,有的代码没有,会导致TaskGroup的ABI不兼容:
   
   https://github.com/apache/incubator-brpc/blob/master/src/bthread/task_group.h#L224
   
   从而影响_cur_meta字段的读取


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1342256989

   再对比一下g、g->current_task()在日志和在gdb中的值看看


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的tid 100次执行的都是一个值,对应的stack这个指针是空,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1341892154

   贴下代码吧


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1343861542

   看起来就是
   g->current_task()获取到的值不等于g->_cur_meta
   但是代码就是这样写的:
   
   ```cpp
   TaskMeta* current_task() const { return _cur_meta; }
   ```
   
   感觉可能是编译器的bug,你可尝试关闭编译优化,看看问题是否还出现


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1343866194

   > 看起来就是 g->current_task()获取到的值不等于g->_cur_meta 但是代码就是这样写的:
   > 
   > ```c++
   > TaskMeta* current_task() const { return _cur_meta; }
   > ```
   > 
   > 感觉可能是编译器的bug,你可尝试关闭编译优化,看看问题是否还出现
   
   我也这么猜测的, 晚点试试看


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1346251636

   @jiangdongzi 试试PR #2047 能否解决这个问题


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1341969283

   > 贴下代码吧
   
   ![image](https://user-images.githubusercontent.com/17529657/206354349-c8929561-2d0e-40e5-a8e2-79f4f43ed649.png)
   这个简单的demo执行是正常的, 我们的服务器上打印不正常, 打印的所有cur_stack都是一个值, 所以的cur_tid都是0, 而, 这个demo不是 (基本完全一样的代码),  唯一的区别是, demo的 bthread_start_backgroud是在主线程执行, 而我们服务器上是在 pthread_create 出来的线程中执行的.  但是 bthread_start_backgroud 返回的tid是正确的值, 就是在真正的逻辑中打印的tid都是0, stack都是同一值, 但是看日志又是并发的, 不是串行的,  而打印的stack是一个值, 我理解应该是串行的, 这就矛盾了, 麻烦帮忙看看, 有什么可能导致了服务和demo的不同


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1342070190

   可以在你服务器上执行函数里加个abort,看一下堆栈吗


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1341971247

   > 
   
   我在 RunClosure中加睡眠, 无论bthread_usleep还是 usleep, 都是同样的结果. is_main_task 在demo中基本都是false, 而在我们的服务器上绝大部分是true, 很偶尔会有false


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1342103596

   > 可以在你服务器上执行函数里加个abort,看一下堆栈吗
   
   ![image](https://user-images.githubusercontent.com/17529657/206369545-8ded25c5-1065-4536-90a8-eb897280e1ad.png)
   调用bthread_start_back_groud之前的堆栈


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1342123494

   > 可以在你服务器上执行函数里加个abort,看一下堆栈吗
   
   ![image](https://user-images.githubusercontent.com/17529657/206372447-05032fd0-29a0-4226-9492-8d430538f54d.png)
   bthread环境下的堆栈


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #2042: 普通线程中调用bthread_start_background100次,在函数中打印对应的stack 100次执行的都是一个值,对应的cur_tid都是0,我打印前是取出来对应的值赋值局部变量打印的

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #2042:
URL: https://github.com/apache/incubator-brpc/issues/2042#issuecomment-1343784149

   > 再对比一下g、g->current_task()在日志和在gdb中的值看看
   
   ![image](https://user-images.githubusercontent.com/17529657/206615243-0af5eea4-fb92-483e-87ef-85cd018f79d5.png)
   


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org