Your SlideShare is downloading. ×
TPL入門
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

TPL入門

4,639
views

Published on

2011/09/17 …

2011/09/17
Hokuriku.NET C# -TPL入門- セッション資料

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,639
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1.    
  • 2.   堅牢性 信頼性 応答性
  • 3.    堅牢性 信頼性 応答性
  • 4.   堅牢性 信頼性 応答性
  • 5.  
  • 6.    
  • 7. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. using System; using System.Linq; using System.Threading; namespace ConsoleApplication { class Program { static void Main() { int lower = 0; int upper = 10000; var source = Enumerable.Range(lower, upper).ToArray(); int chunk = (upper - lower) / Environment.ProcessorCount; var threads = new Thread[Environment.ProcessorCount]; for (int i = 0; i < threads.Length; i++) { int start = chunk * i + lower; int end = i < threads.Length - 1 ? start + chunk : upper; threads[i] = new Thread(() => { for (int j = start; j < end; j++) { //----- Do Something Console.WriteLine(source[j]); } }); } } } } foreach (var thread in threads) thread.Start(); foreach (var thread in threads) thread.Join();
  • 8. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. using System; using System.Linq; using System.Threading; namespace ConsoleApplication { class Program { static void Main() { int lower = 0; int upper = 10000; var source = Enumerable.Range(lower, upper).ToArray(); int chunk = (upper - lower) / Environment.ProcessorCount; var threads = new Thread[Environment.ProcessorCount]; for (int i = 0; i < threads.Length; i++) { int start = chunk * i + lower; int end = i < threads.Length - 1 ? start + chunk : upper; threads[i] = new Thread(() => { for (int j = start; j < end; j++) { //----- Do Something Console.WriteLine(source[j]); } }); } } } } foreach (var thread in threads) thread.Start(); foreach (var thread in threads) thread.Join();
  • 9. 1. 2. 3. using System; using System.Linq; using System.Threading.Tasks; 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. namespace ConsoleApplication { class Program { static void Main() { int lower = 0; int upper = 10000; var source = Enumerable.Range(lower, upper).ToArray(); Parallel.For(lower, upper, index => { //----- Do Something Console.WriteLine(source[index]); }); } } }
  • 10.  実CPUに割り当てるスレッドの切り替え   タイムスライスの後に同じスレッドが割り当 てられる場合は発生しない
  • 11.   
  • 12. CLR ThreadPool UI Thread Local Queue 1 Local Queue 2 Worker Thread 1 Global Queue Worker Thread 2 詳しくはWebで!!
  • 13.  
  • 14. コレクション 要素 パーティション スレッドプール スレッド
  • 15.   
  • 16.  
  • 17.  タスク並列ライブラリ  .NET アプリケーションの並列処理について の過去、現在、未来  .NETマルチスレッド・プログラミング入門  [雑記] スレッド プールとタスク  プログラミング .NET Framework 第3版  TPL入門 - インデックス
  • 18. Let’s enjoy TPL!!