introduction to tpl

Download Introduction to TPL

Post on 10-May-2015

575 views

Category:

Technology

2 download

Embed Size (px)

DESCRIPTION

TPL(Task Parallel Library)에 대한 소개입니다. 데모 코드 - Multi Threading https://github.com/gyuwon/DotNetPractice/blob/master/Tasks/MultiThreading/Program.cs - Shard Resource Access https://github.com/gyuwon/DotNetPractice/blob/master/Tasks/SharedResourceAccess/Program.cs - Continuation https://github.com/gyuwon/DotNetPractice/blob/master/Tasks/Chapters/Program.cs - Parallelism Performance https://github.com/gyuwon/DotNetPractice/blob/master/Tasks/ParallelismPerformance/Program.cs - foreach vs. ForAll https://github.com/gyuwon/DotNetPractice/blob/master/Tasks/ForAll/Program.cs

TRANSCRIPT

  • 1.TPL(Task Parallel Library) (gyuwon@live.com) http://justhackem.wordpress.com https://www.facebook.com/gyuwon.yi

2. Background 3. Thread (CPU Time) Multi Threading Parallel Processing UI & Background Tasks Shared Resource Access 4. DEMO Multi Threading Shared Resource Access 5. Thread Pool Recycling Thread Pool Thread Thread Thread Work Item Queue 6. Future Future Promise 7. Tasks 8. Task Task Thread Task is a Work Item (IThreadPoolWorkItem) Future Awaitable Task Scheduler 9. Default Task Scheduler Thread Pool Worker Thread Local Queue Worker Thread Local Queue Global Queue Task Task Task Task Task Task Task Task LIFO LIFO FIFO Work Stealing 10. Start protected internal override void QueueTask(Task task) { if ((task.Options & TaskCreationOptions.LongRunning) != 0) { Thread thread = new Thread(); thread.IsBackground = true; thread.Start(task); } else { ThreadPool.UnsafeQueueCustomWorkItem(task, ); } } 11. FromAsync internal static Task FromAsyncImpl(IAsyncResult asyncResult, ) { Task t = new Task(); if (asyncResult.IsCompleted) { t.InternalRunSynchronously(); } else { ThreadPool.RegisterWaitForSingleObject(); } } 12. Result TResult Task.Result 13. Continuation Task Task ContinueWith GetAwaiter 14. ContinueWith internal void ContinueWithCore(Task continuationTask, ...) { if (!continuationTask.IsCompleted) { // Attempt to enqueue the continuation bool continuationQueued = AddTaskContinuation(); // If the continuation was not queued (because the task completed), then run it now. if (!continuationQueued) continuation.Run(this, ); } } 15. DEMO Continuation 16. PLINQ(Parallel Linq) 17. Data Parallelism Sequential Parallel Processor Processor Processor Processor 18. Parallel Query Query from e in query where select Parallel Query from e in query.AsParallel() where select 19. DEMO Performance 20. foreach vs. ForAll foreach ForAll Proc A Proc A Proc A Proc B Proc A Proc A Proc A Proc B Proc B Proc B 21. DEMO foreach vs. ForAll