legionxiong commented on code in PR #2333:
URL: https://github.com/apache/brpc/pull/2333#discussion_r1299548891
##########
src/bthread/execution_queue.cpp:
##########
@@ -105,16 +106,34 @@ void ExecutionQueueBase::start_execute(TaskNode* node) {
}
if (nullptr == _options.executor) {
- bthread_t tid;
- // We start the execution thread in background instead of foreground as
- // we can't determine whether the code after execute() is urgent (like
- // unlock a pthread_mutex_t) in which case implicit context switch may
- // cause undefined behavior (e.g. deadlock)
- if (bthread_start_background(&tid, &_options.bthread_attr,
- _execute_tasks, node) != 0) {
- PLOG(FATAL) << "Fail to start bthread";
- _execute_tasks(node);
+ if (_options.use_pthread) {
+ if (_pthread_started) {
+ BAIDU_SCOPED_LOCK(_mutex);
+ _current_head = node;
+ _cond.Signal();
+ } else {
+ // Start the execution bthread in background once.
+ if (pthread_create(&_pid, NULL,
Review Comment:
This may cause hundreds of threads being created.
--
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]