darion-yaphet commented on code in PR #3638:
URL: https://github.com/apache/brpc/pull/3638#discussion_r4345013524


##########
src/bthread/key.cpp:
##########
@@ -334,9 +339,10 @@ KeyTable* borrow_keytable(bthread_keytable_pool_t* pool) {
                     return p;
                 }
             }
+            has_free_keytables = pool->free_keytables != nullptr;
             pthread_rwlock_unlock(&pool->rwlock);
         }
-        if (pool->free_keytables) {
+        if (has_free_keytables) {

Review Comment:
   The snapshot can miss a KeyTable returned immediately after the read lock is 
released, but the previous unlocked check had the same timing window.
   
   Taking the write lock whenever the local cache is empty may reduce missed 
reuse but could also increase contention. I suggest evaluating that as a 
separate performance optimization with benchmarks.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to