Skip to content

Instantly share code, notes, and snippets.

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

  • Save ierhalim/38e30d3e3e4d4ac17469b800e24db5af to your computer and use it in GitHub Desktop.

Select an option

Save ierhalim/38e30d3e3e4d4ac17469b800e24db5af to your computer and use it in GitHub Desktop.
Y2O1 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>();
for (int i = 0; i < 15; i++)
{
tasks.Add(Task.Factory.StartNew(() =>
{
for (int j = 0; j < 20; j++)
{
// Atomik olmayan işlem.
number++;
}
}));
tasks.Add(Task.Factory.StartNew(() =>
{
for (int j = 0; j < 20; j++)
{
// Atomik olmayan işlem.
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