chenBright opened a new pull request, #3351:
URL: https://github.com/apache/brpc/pull/3351

   ### What problem does this PR solve?
   
   Issue Number: resolve #3349
   
   Problem Summary:
   
   `bthread_stop()` calls `bthread_interrupt(tid)`, which uses the default
   argument `BTHREAD_TAG_DEFAULT = 0`. When a non-worker thread (e.g. the
   main thread during `Server::~Server()` -> `Join()`) stops a bthread with 
`tag > 0`, 
   `TaskGroup::interrupt()` takes the 
`c->choose_one_group(tag)->ready_to_run_remote(m)` 
   path with `tag == 0`. As a result, the interrupted bthread is re-scheduled 
onto a 
   worker of tag 0 instead of its own tag group, breaking tag isolation.
   
   ### What is changed and the side effects?
   
   Changed:
   
   The tag of a bthread is already recorded in its `TaskMeta`
   (`m->attr.tag`), so passing the tag explicitly is unnecessary and
   error-prone. Instead of forwarding the (default) tag argument, the code
   now reads the tag from the target `TaskMeta`:
   
   - `bthread_interrupt(bthread_t, bthread_tag_t)`: the `tag` parameter is
     now ignored (kept only for API/ABI compatibility) and the call
     delegates to `TaskGroup::interrupt(tid, control)`.
   - `TaskGroup::interrupt()`: the `tag` parameter is removed; the target
     group is chosen via `c->choose_one_group(m->attr.tag)`.
   - `butex.cpp`: the redundant `ButexBthreadWaiter::tag` field is removed;
     `butex_wake`, `butex_wake_n`, `butex_wake_except`, `butex_requeue` and
     `erase_from_butex` now obtain the tag from `task_meta->attr.tag`.
   
   Side effects:
   - Performance effects:
   
   - Breaking backward compatibility: 
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
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