MCSD C# 01.01 Implement Multithreading and Asynchronous Processing.txt
Home > Preview
The flashcards below were created by user
on FreezingBlue Flashcards.
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.
What is context switching
Refers to how Windows runs each thread for a set time then pauses thread and switches to another
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.
What does it mean when a program has parallelism?
The program can execute multiple threads on different CPUs in parallel.
Name 1 disadvantage and 2 advantages of using threads.
Threads have an associated overhead, but can improve scalability or responsiveness.
What namespace does the Thread class belong to?
What 3 things does the Thread class enable?
- 1. Creation of threads
- 2. Managing thread priority
- 3. Obtaining thread status
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.
What is the code to execute a new thread?
Thread t = new Thread(new ThreadStart(ThreadMethod));
What code causes windows to immediately switch to next thread?
What code would block the calling thread until another thread has finished.
- (where Threadname is the name of the thread you want to wait to finish)
(a) What property of the Thread class gives the priority of the thread
(b) What is the default priority for a thread?
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.
What is the code for a parameterized thread start
Thread t = new Thread(new ParameterizedThreadStart(ThreadMethod));
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.
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.
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.
- Public static int _field
- From above, every thread will have it’s own _field value, otherwise each thread would share the _field value.
What Thread class property gives access to information about the thread
What is the information called that Thread.CurrentThread gives access to?
The execution context of the thread
Give 3 examples of information contained within a thread's execution context
- current culture
- principal (current security context)
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