Skip to content

Instantly share code, notes, and snippets.

@ierhalim
Last active December 27, 2020 11:59
Show Gist options
  • Select an option

  • Save ierhalim/8005c3b3a9f2d88299cf7d511449ff6e to your computer and use it in GitHub Desktop.

Select an option

Save ierhalim/8005c3b3a9f2d88299cf7d511449ff6e to your computer and use it in GitHub Desktop.
Y2O4 Paralel programlama
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DataSharing
{
class Program
{
static void Main(string[] args)
{
var readerWriterLock = new ReaderWriterLockSlim();
int value = 10;
Console.WriteLine("Press a key to increase the number");
var task = Task.Run(() =>
{
while (true)
{
try
{
readerWriterLock.EnterReadLock();
Console.WriteLine(value);
Thread.Sleep(5000);
}
finally
{
readerWriterLock.ExitReadLock();
}
}
});
while (true)
{
Console.ReadKey();
readerWriterLock.EnterWriteLock();
value++;
readerWriterLock.ExitWriteLock();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment