Your SlideShare is downloading. ×
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Introduction to TPL
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to TPL

576

Published on

TPL(Task Parallel Library)에 대한 소개입니다. …

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

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
576
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
8
Comments
0
Likes
2
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. 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<TResult>.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

×