mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
Add samples/, a collection of single-file .NET 10 apps run with `dotnet run <file>.cs`. Hello/ has one minimal sample per package that has a public API, many of them headless; Demo/ has fuller programs that combine packages into a more interesting application. samples/README.md indexes every sample and covers the layout, error handling and per-OS requirements.
27 lines
801 B
C#
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.1
|
|
|
|
// 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}");
|
|
}
|