Last active
December 27, 2020 17:41
-
-
Save ierhalim/e628668153b452550e3b9bedaed59262 to your computer and use it in GitHub Desktop.
Y4O1 Paralel programlama
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| namespace ConcurentCollections | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var list = new List<int>(); | |
| var tasks = new List<Task>(); | |
| for (int i = 1; i < 5; i++) | |
| { | |
| // Taskler başlayana kadar döngü biteceği için tüm threadlerde i nin değeri 4 olacaktır, bunu engellemek adına i yi her scope için farklı bir değere atıyoruz. | |
| int copyOfi = i; | |
| tasks.Add(Task.Run(() => | |
| { | |
| Console.WriteLine("Task {0} Add {1}", Task.CurrentId, copyOfi); | |
| list.Add(copyOfi); | |
| int result = list.Last(); | |
| Console.WriteLine("Task {0} Last record {1}", Task.CurrentId, result); | |
| })); | |
| } | |
| Task.WaitAll(tasks.ToArray()); | |
| Console.ReadKey(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment