brutal/samples/Hello/HelloConcurrency.cs
Rian Drake d1ce547eb2 samples: bump every package pin to the latest release
Fixes #38

Co-authored-by: LesoDeVaren <268139647+LesoDeVaren@users.noreply.github.com>
2026-11-03 11:43:45 +13:00

27 lines
801 B
C#

/*
* HelloConcurrency
*
* Runs a few jobs across worker threads with the JobScheduler and waits for them to finish.
*/
#:package Ahwoo.Brutal.Concurrency@2026.10.2
// RIAN: This job system is finely-tuned for the way RW projects like to implement concurrency, and has limitations we should document at some stage.
using Brutal.Concurrency.Jobs;
var scheduler = new JobScheduler(3, "HelloScheduler");
// The second argument is an estimated cost, used to balance jobs across worker threads.
for (var i = 1; i <= 6; i++)
scheduler.Queue(new HelloJob(i), 10);
scheduler.ExecuteJobs();
scheduler.Wait();
Console.WriteLine("All jobs finished");
class HelloJob(int id) : IJob
{
public void Run() => Console.WriteLine($"Job {id} running on thread {Environment.CurrentManagedThreadId}");
}