Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


wwbmmm commented on PR #2517:
URL: https://github.com/apache/brpc/pull/2517#issuecomment-1905236057

   LGTM


-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461997899


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   mutex/cond比bthread_usleep优雅,但是没有合适的位置初始化mutex/cond。



-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461769853


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   或者自旋一定次数后,进入slow path(bthread_usleep 
1ms),这样可以自适应地防止死锁问题,不需要使用者设置。因为很多时候,使用者需要等到死锁了才会发现有挂起协程的需求。可以自适应的话,可以完全规避这个问题。



-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461769853


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   
或者自旋一定次数后,再调bthread_usleep,这样可以自适应地防止死锁问题,不需要使用者设置。因为很多时候,使用者需要等到死锁了才会发现有挂起协程的需求。可以自适应的话,可以完全规避这个问题。



-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461769853


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   
或者自旋一定次数后,再调bthread_yield/bthread_usleep,这样可以自适应地防止死锁问题,不需要用户设置。因为很多时候,用户需要等到死锁了才会发现有bthread_yield的需求。可以自适应的话,可以完全规避这个问题。



-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461769853


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   
或者自旋一定次数后,再调bthread_yield/bthread_usleep,这样可以自适应地防止死锁问题,不需要使用者设置。因为很多时候,使用者需要等到死锁了才会发现有bthread_yield的需求。可以自适应的话,可以完全规避这个问题。



-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461769853


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   
或者自旋一定次数后,再调bthread_yield,这样可以自适应地防止死锁问题,不需要用户设置。因为很多时候,用户需要等到死锁了才会发现有bthread_yield的需求。可以自适应的话,可以完全规避这个问题。



-- 
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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-22 Thread via GitHub


chenBright commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461474105


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   Singleton加个模板参数,控制是否使用bthread_yield,默认值为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-unsubscr...@brpc.apache.org

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


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



Re: [PR] Support bthread_yield to wait for Singleton in bthread (brpc)

2024-01-21 Thread via GitHub


wwbmmm commented on code in PR #2517:
URL: https://github.com/apache/brpc/pull/2517#discussion_r1461431437


##
src/butil/memory/singleton.cc:
##
@@ -5,9 +5,23 @@
 #include "butil/memory/singleton.h"
 #include "butil/threading/platform_thread.h"
 
+__BEGIN_DECLS
+// Defined in bthread/bthread.cpp
+void BAIDU_WEAK bthread_yield();
+__END_DECLS
+
 namespace butil {
 namespace internal {
 
+void yield() {
+if (bthread_yield) {

Review Comment:
   是不是加个开关控制一下?毕竟大部分Singleton场景,是不需要bthread_yield的



-- 
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-unsubscr...@brpc.apache.org

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


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