Anda di halaman 1dari 6

HaNoi University of Technology

Week 11: Threading in C#- Mastering C# 2008

Week 11: Threading in C#


Topics
Threading in C# and .NET 11.2 Synchronizing Work Between Threads 11.3 Using ThreadPool

Concept review
Thread Priorities Thread scheduling States of a Thread o Unstarted o Started o Running o Finshed/Aborted o WaitSleepJoin o Suspended Using ThreadPool o Asynchronous Method Calls Using ThreadPool o Timers

1/6

HaNoi University of Technology

Week 11: Threading in C#- Mastering C# 2008

Exercise 1 Asynchronous execution techniques allow you to... Share a single processor more naturally across unrelated tasks Prioritize tasks relative to one another to achieve a desired level of responsiveness Multiplex I/O operations to avoid cumulative waiting Perform computationally intensive tasks concurrently on multiple processors All of the above None of the above Answer__________________________________________

Exercise 2 True or false: using multiple threads always results in a performance improvement True False Answer______________________________________

Exercise 3 Which of the following statements is true?

2/6

HaNoi University of Technology

Week 11: Threading in C#- Mastering C# 2008

Multithreading is so easy, everyone should be doing it If a multithreading program runs correctly once, it's ready to ship Debugging multithreaded programs is as easy as debugging single threaded programs All of the above None of the above Answer______________________________________

Exercise 4 True or false: delegates provide a type-safe way to place asynchronous method calls against arbitrary methods. True False Answer______________________________________

Exercise 5 True or false: each call to BeginInvoke against a delegate causes the runtime to create a new thread. True False

Answer_____________________________________________________ Exercise 6 In order to wait for an asynchronous method initiated using Delegate.BeginInvoke call to complete, you may do which of the following:

3/6

HaNoi University of Technology

Week 11: Threading in C#- Mastering C# 2008

Block until WaitHandle returned by IAsyncResult.AsyncWaitHandle is signalled Request a callback using the AsyncCallback argument to BeginInvoke Poll the IsCompleted property of IAsyncResult Call EndInvoke Any of the above None of the above

Answer_____________________________________________________

Exercise 7 Under what circumstances might you elect to use explicit threading as opposed to the thread-pooling techniques? When you're performing very lengthy operations When you need to prioritize tasks relative to each other When you need to control COM apartment affiliation when doing COM interop When you want a thread's existence to keep the process from exiting Any of the above None of the above Answer____________________________________________

Exercise 8 True or false: by default, all CLR objects are thread-safe. True False Answer____________________________________________ Exercise 9

4/6

HaNoi University of Technology

Week 11: Threading in C#- Mastering C# 2008

True or false: reading shared data structures concurrently from multiple threads is always thread-safe. True False Answer____________________________________________

Exercise 10 True or false: modifying shared data structures concurrently from multiple threads is always thread-safe. True False Answer____________________________________________

Exercise 11 True or false: the Monitor can be used to ensure singlethreaded access to shared resources. True False Answer____________________________________________

Exercise 12

5/6

HaNoi University of Technology

Week 11: Threading in C#- Mastering C# 2008

True or false: if one thread acquires ownership of the lock used to serialize access to an object, the CLR automatically prevents other threads from accessing that same object whether or not they also try to grab its associated lock. True False Answer____________________________________________

6/6

Anda mungkin juga menyukai