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 2020/06/29 16:30:13 UTC

[GitHub] [incubator-brpc] triump2020 opened a new issue #1150: resource_pool_inl.h 中 add_block 函数 关于Lock-Free 的问题??

triump2020 opened a new issue #1150:
URL: https://github.com/apache/incubator-brpc/issues/1150


   Hi  Contributors and Jamesge !
   
          Brpc 在性能上确实优于很多目前rpc 框架, 但是在看源码过程中,发现resource_pool_inl.h 中 add_block 函数好像有个问题, 当然也有可能是我的误解,望解答,谢谢!  下面是add_block 函数中的 一个do-while 循环,问题出在do-while 的最后返回new_block 的地方,这个new_block 在返回之前,没有加Acquire 语义。
         
     
         do {
               //这里的_ngroup 不一定能拿到最新值.
               ngroup = _ngroup.load(butil::memory_order_acquire);
               if (ngroup >= 1) {
                   BlockGroup* const g =
                       _block_groups[ngroup - 1].load(butil::memory_order_consume);
                   const size_t block_index =
                       g->nblock.fetch_add(1, butil::memory_order_relaxed);
                   //        如果上面的_ngroup 取到的是一个旧值,则下面的if 条件不会成立
                   //         然后进入add_block_group, 而add_block_group 里有加锁操作
                   //         可以拿到最新的_ngroup 值, 程序是安全的.
                   if (block_index < RP_GROUP_NBLOCK) {
                       //      ****问题:****
                       //       这里strore用了release 语义,
                       //        但是返回new_block 之前,没有加上对应的Acquire语义???
                       g->blocks[block_index].store(
                           new_block, butil::memory_order_release);
                       *index = (ngroup - 1) * RP_GROUP_NBLOCK + block_index;
                       return new_block;
                   }
                   g->nblock.fetch_sub(1, butil::memory_order_relaxed);
               }
           } while (add_block_group(ngroup));
   
   
   
   
   
   **Describe the bug (描述bug)**
   
   
   **To Reproduce (复现方法)**
   
   
   **Expected behavior (期望行为)**
   
   
   **Versions (各种版本)**
   OS:
   Compiler:
   brpc:
   protobuf:
   
   **Additional context/screenshots (更多上下文/截图)**
   
   


----------------------------------------------------------------
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.

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] triump2020 closed issue #1150: resource_pool_inl.h 中 add_block 函数 关于Lock-Free 的问题??

Posted by GitBox <gi...@apache.org>.
triump2020 closed issue #1150:
URL: https://github.com/apache/incubator-brpc/issues/1150


   


----------------------------------------------------------------
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.

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] triump2020 commented on issue #1150: resource_pool_inl.h 中 add_block 函数 关于Lock-Free 的问题??

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


   同一个线程里,对同一个原子变量的读写不会乱序


----------------------------------------------------------------
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.

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