Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scheduling-threads.md added an example code #40739

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

victoravt
Copy link

@victoravt victoravt commented May 3, 2024

Summary

The example demonstrates the prioritization of threads in action and gives code base for readers to copy and experiment with.

Describe your changes here.
Added an example code with description.

Fixes #Issue_Number (if available)
No issue.


Internal previews

馃搫 File 馃敆 Preview link
docs/standard/threading/scheduling-threads.md Scheduling threads

Added an example code with description.
@victoravt victoravt requested a review from BillWagner as a code owner May 3, 2024 12:39
@dotnet-bot dotnet-bot added this to the May 2024 milestone May 3, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates PR is created by someone from the .NET community. label May 3, 2024
@victoravt
Copy link
Author

@dotnet-policy-service agree

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @victoravt

This is an important sample to add. Thank you.

I had a few comments for updates, and then this is ready to merge.

docs/standard/threading/scheduling-threads.md Outdated Show resolved Hide resolved

The following code will output arbitrary results on each execution. But common sequence patters of priorities being ran could be observed after running multiple times and analyzing the outputs.

```c#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For samples, we've been moving toward including samples as code files using the ::: code extension. That enables our CI system to validate the code. Can you move the sample code into a project and include the code here?

Comment on lines +48 to +56
Thread t0 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t1 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t2 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t3 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t4 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t5 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t6 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t7 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Thread t8 = new Thread(() => { new ThreadWithCallback(Callback).Process(); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a log of opportunity to refactor this so it's got less repeated code. Maybe store the threads in an array and loop through the creation, setting priority, and start code?

Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants