wwbmmm commented on code in PR #2225: URL: https://github.com/apache/brpc/pull/2225#discussion_r1200411426
########## src/butil/containers/doubly_buffered_data.h: ########## @@ -49,10 +51,38 @@ namespace butil { // foreground and background, lock thread-local mutexes one by one to make // sure all existing Read() finish and later Read() see new foreground, // then modify background(foreground before flip) again. +// +// But, when `AllowSuspendBthread=false', it is not allowed to suspend bthread +// while reading. Otherwise, it may cause deadlock. +// +// +// --- `AllowSuspendBthread=true' --- +// It is allowed to suspend bthread while reading. +// It is not allowed to use non-Void TLS. +// If bthread will not be suspended while reading, it also makes Read() almost +// lock-free by making Modify() *much* slower. +// If bthread will be suspended while reading, there is competition among +// bthreads using the same Wrapper. +// +// Read(): Begin with thread-local reference count of foreground instance +// incremented by one which be protected by a thread-local mutex, then read +// the foreground instance which will not be changed before its all thread-local +// reference count become zero. At last, after the query completes, thread-local +// reference count of foreground instance will be decremented by one, and if +// it becomes zero, notifies Modify(). +// +// Modify(): Modify background instance which is not used by any Read(), flip +// foreground and background, lock thread-local mutexes one by one and wait +// until thread-local reference counts which be protected by a thread-local +// mutex become 0 to make sure all existing Read() finish and later Read() +// see new foreground, then modify background(foreground before flip) again. class Void { }; -template <typename T, typename TLS = Void> +template <typename T> struct is_Void : false_type { }; Review Comment: IsVoid 可以么 -- 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