Skip to content

Instantly share code, notes, and snippets.

@ierhalim
Created December 27, 2020 11:31
Show Gist options
  • Select an option

  • Save ierhalim/90588e97650231a2ea1870143a3ad9ec to your computer and use it in GitHub Desktop.

Select an option

Save ierhalim/90588e97650231a2ea1870143a3ad9ec to your computer and use it in GitHub Desktop.
Y2O2 Paralel programlama
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DataSharing
{
class Program
{
static void Main(string[] args)
{
int number = 0;
var tasks = new List<Task>();
object locker = new object();
for (int i = 0; i < 15; i++)
{
tasks.Add(Task.Factory.StartNew(() =>
{
for (int j = 0; j < 20; j++)
{
lock (locker)
{
number++;
}
}
}));
tasks.Add(Task.Factory.StartNew(() =>
{
for (int j = 0; j < 20; j++)
{
lock (locker)
{
number--;
}
}
}));
}
Task.WaitAll(tasks.ToArray());
Console.WriteLine(number);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment