Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,29 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace RosettaCode
{
internal sealed class Program
{
private static void Worker(object arg, int id)
{
var sem = arg as SemaphoreSlim;
sem.Wait();
Console.WriteLine("Thread {0} has a semaphore & is now working.", id);
Thread.Sleep(2*1000);
Console.WriteLine("#{0} done.", id);
sem.Release();
}
private static void Main()
{
var semaphore = new SemaphoreSlim(Environment.ProcessorCount*2, int.MaxValue);
Console.WriteLine("You have {0} processors availiabe", Environment.ProcessorCount);
Console.WriteLine("This program will use {0} semaphores.\n", semaphore.CurrentCount);
Parallel.For(0, Environment.ProcessorCount*3, y => Worker(semaphore, y));
}
}
}