Performance of CancellationToken::clone VS CancellationToken::child_token with large amount of tasks #7945
Answered
by
Darksonn
ultimaweapon
asked this question in
Q&A
-
|
Let's say I have 1 million of tasks that need to be canceled with a single loop {
select! {
biased; // Stop immediately when shutdown.
_ = running.cancelled() => break,
// There are other statements here depend on task's job.
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
Darksonn
Mar 3, 2026
Replies: 1 comment 1 reply
-
|
The If you do not require partial cancellations, do not use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ultimaweapon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
clone()andchild_token()methods do not do the same thing. The child token allows you to perform partial cancellations becausechild.cancel()does not affect the parent, butparent.cancel()will affect the child.If you do not require partial cancellations, do not use
child_token(). In that case,clone()is far more efficient.