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/04/13 16:26:07 UTC

[GitHub] [incubator-brpc] stdpain opened a new issue, #1741: bthread dead lock when yield with a lock

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

   **Describe the bug (描述bug)**
   
   **To Reproduce (复现方法)**
   ```
   std::mutex _mutex;
   
   void* func(void*) {
       std::cout << "BEFOREc" << bthread_self() << std::endl;
       {
           std::lock_guard<std::mutex> g(_mutex);
           std::cout << "HELLO" << bthread_self() << std::endl;
           bthread_yield();
           sleep(1);
       }
       std::cout << "I'm free" << bthread_self() << std::endl;
       return nullptr;
   }
   
   int main() {
       bthread_attr_t attr;
       bthread_attr_init(&attr);
   
       bthread_setconcurrency(1);
       bthread_t threads[100];
       for (int i = 0; i < 100; ++i) {
           bthread_start_urgent(&threads[i], &attr, func, nullptr);
       }
   
       sleep(60);
     return 0;
   }
   ```
   
   
   **Expected behavior (期望行为)**
   
   **Versions (各种版本)**
   OS:
   Compiler:
   brpc: 0.9.7
   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.

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] stdpain closed issue #1741: bthread dead lock when yield with a lock

Posted by GitBox <gi...@apache.org>.
stdpain closed issue #1741: bthread dead lock when yield with a lock
URL: https://github.com/apache/incubator-brpc/issues/1741


-- 
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] cooper-zhzhang commented on issue #1741: bthread dead lock when yield with a lock

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang commented on issue #1741:
URL: https://github.com/apache/incubator-brpc/issues/1741#issuecomment-1100033575

   ```
   //get 5 pthread in system
   bthread_setconcurrency(5)
   // get 6 bthread
     for (int i = 0; i < 6; ++i) {
           bthread_start_urgent(&threads[i], &attr, func, nullptr);
       }
   
   ```
   
   
   pthread 0: . run bthread0-->   lock _mutex --> bthread_yield() --> run bthread5 --> wait _mutex  
   pthread 1: run bthread1 --> wait _mutex
   pthread 2: run bthread2 --> wait _mutex
   pthread 3: run bthread3 --> wait _mutex
   pthread 4: run bthread4 --> wait _mutex
   
   
   
   
   
   
   
   
   
   
   


-- 
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] serverglen commented on issue #1741: bthread dead lock when yield with a lock

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

   I think the reasons are as follows
   1. worker threads number is too small
   2. avoid using blocking pthread API in bthreads, use the corresponding data structure in bthread for example bthread_mutex_t and bthread_cond_t
   3. if must use the blocking pthread API, keep the critical sections small


-- 
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] cooper-zhzhang commented on issue #1741: bthread dead lock when yield with a lock

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang commented on issue #1741:
URL: https://github.com/apache/incubator-brpc/issues/1741#issuecomment-1098826265

    bthread_setconcurrency(1);
    这里会有问题,并发量有限制 不能过小


-- 
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 #1741: bthread dead lock when yield with a lock

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

   bthread_setconcurrency(1) will not take effect because BTHREAD_MIN_CONCURRENCY is 4.


-- 
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] stdpain commented on issue #1741: bthread dead lock when yield with a lock

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

   It looks like this, assuming there is only one worker.
   The worker schedules bthread1 to get the lock on the pthread and then performs a yield.
   The worker schedules bthread2 to try to get the pthread lock, and then blocks.
   
   Since worker is blocked, it cannot schedule bthread1, so bthread1 cannot release the lock, resulting in a deadlock.
   
   The main reason is not that the bthread_setconcurrency is too small. Because even if the worker is large, it will still get stuck, but the probability is very low.


-- 
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 #1741: bthread dead lock when yield with a lock

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

   > ```
   > //get 5 pthread in system
   > bthread_setconcurrency(5)
   > // get 6 bthread
   >   for (int i = 0; i < 6; ++i) {
   >         bthread_start_urgent(&threads[i], &attr, func, nullptr);
   >     }
   > ```
   > 
   > pthread 0: . run bthread0--> lock _mutex --> bthread_yield() --> run bthread5 --> wait _mutex pthread 1: run bthread1 --> wait _mutex pthread 2: run bthread2 --> wait _mutex pthread 3: run bthread3 --> wait _mutex pthread 4: run bthread4 --> wait _mutex
   > 
   > @
   
   This result is expected, according to the design of 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