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 2021/03/16 04:46:26 UTC

[GitHub] [incubator-brpc] SF-Zhou opened a new pull request #1358: Fix deadlock in TaskGroup::push_rq

SF-Zhou opened a new pull request #1358:
URL: https://github.com/apache/incubator-brpc/pull/1358


   This is a known bug in src/bthread/task_group_inl.h. It will cause a deadlock when all workers are spinning in `TaskGroup::push_rq`. A reproducible code:
   ```c++
   #include <bthread/bthread.h>
   
   static std::atomic<size_t> value{0};
   
   void* do_job(void*) {
     ++value;
     return nullptr;
   }
   
   void* start(void*) {
     const uint32_t M = 10000;  // bigger than default queue capacity
     std::vector<bthread_t> tids(M);
     for (auto& tid : tids) {
       bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, do_job, nullptr);
     }
     for (auto& tid : tids) {
       bthread_join(tid, nullptr);
     }
     return nullptr;
   }
   
   int main(int argc, char* argv[]) {
     const uint32_t N = 10;  // bigger than default concurrency
   
     std::vector<bthread_t> tids(N);
     for (auto& tid : tids) {
       bthread_start_urgent(&tid, &BTHREAD_ATTR_SMALL, start, nullptr);
     }
     for (auto& tid : tids) {
       bthread_join(tid, nullptr);
     }
     printf("Value = %lu\n", value.load());
     return 0;
   }
   ```


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