MCSD C# 01.01 Implement Multithreading and Asynchronous Processing.txt

Card Set Information

Author:
alan43tod
ID:
279344
Filename:
MCSD C# 01.01 Implement Multithreading and Asynchronous Processing.txt
Updated:
2014-07-20 21:01:10
Tags:
MCSD Chapter 01
Folders:

Description:
MCSD C# 01.01 Implement Multithreading and Asynchronous Processing
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user alan43tod on FreezingBlue Flashcards. What would you like to do?


  1. In the context of Threads complete the following...
    Each Application has it's own _______(a).
    _______(a plural) are isolated from each other by having their own  _______(b).
    Each  _______(a) runs in it's own _______(c).
    A _______(c) is something like a  _______(d).
    • Each Application has it’s own Process
    • Processes are isolated from each other by having their own virtual memory
    • Each Process runs in it’s own thread
    • A thread is something like a virtualized CPU.
  2. What is context switching
    Refers to how Windows runs each thread for a set time then pauses thread and switches to another
  3. What are the disadvantages and advantages of context switching?
    Context switching creates overheads, but at least each process gets it’s time to execute, without having to wait for another to finish.
  4. What does it mean when a program has parallelism?
    The program can execute multiple threads on different CPUs in parallel.
  5. Name 1 disadvantage and 2 advantages of using threads.
    Threads have an associated overhead, but can improve scalability or responsiveness.
  6. What namespace does the Thread class belong to?
    System.Threading
  7. What 3 things does the Thread class enable?
    • 1. Creation of threads
    • 2. Managing thread priority
    • 3. Obtaining thread status
  8. In the context of threads, what is Synchronization?
    The mechanism ensuring two threads don’t execute a specific portion of a program at the same time.
  9. What is the code to execute a new thread?
    Thread t = new Thread(new ThreadStart(ThreadMethod));
  10. What code causes windows to immediately switch to next thread?
    Thread.Sleep(0);
  11. What code would block the calling thread until another thread has finished.
    • Threadname.Join();
    • (where Threadname is the name of the thread you want to wait to finish)
  12. (a) What property of the Thread class gives the priority of the thread

    (b) What is the default priority for a thread?
    • (a) Priority
    • (b) Normal
  13. What are the two types of threads. How do they differ?
    • Threads can be foreground or background. An app terminates only when all foreground threads finish.
    • When an app terminates, all background threads from the app are terminated.
  14. What is the code for a parameterized thread start
    Thread t = new Thread(new ParameterizedThreadStart(ThreadMethod));
  15. Why should you not use Thread.Abort to stop a thread?
    Because this method is executed by another thread, it can happen at any time. When Thread.Abort is used, a ThreadAbort-Exception is thrown that can make app unstable.
  16. What does the ThreadStatic attribute do?
    A static field marked with ThreadStatic attribute is not shared between threads. Each executing thread has a separate instance of the field, and independently sets and gets values for that field. If the field is accessed on a different thread, it will contain a different value.
  17. How should you end threads without using Thread.Abort?
    • Instead of Thread.Abort, use a variable accessible to all threads to check whether a thread should stop itself.
    • You can mark a field with ThreadStatic attribute, and every thread gets it’s own copy of that field eg.
    • [ThreadStatic]
    • Public static int _field
    • From above, every thread will have it’s own _field value, otherwise each thread would share the _field value.
  18. What Thread class property gives access to information about the thread
    CurrentThread
  19. What is the information called that Thread.CurrentThread gives access to?
    The execution context of the thread
  20. Give 3 examples of information contained within a thread's execution context
    • current culture
    • principal (current security context)
    • priority
  21. What does ExecutionContext.SuppressFlow do?
    ExecutionContext.SuppressFlow saves overhead by stopping the default behaviour of parent threads being passed to child threads

What would you like to do?

Home > Flashcards > Print Preview