Fichas
Threads
Fichas del conjunto (24)
- 1What is a Thread?It's the smallest sequence of programmed instructions that can be idenpendently managed by the Operating System scheduler.
- 2What is the Threads namespace?System.Threading
- 3What is synchronization?It's a mechanism of ensuring that two processes share the same portion of code at the same time.
- 4What does the Thread class stand for?It is used to manage the application threads in terms of creation, update, priority setting and status update.
- 5What does the Thread.Join() stand for?The join method is called on the main thread to let it wait the other threads to finish.
- 6How do I start a thread?1: Create a ThreadStart/ParameterizedThreadStart delegate object by passing a Method
2: Create a Thread object passing a ThreadStart object
3: Call Thread.Start() - 7Why call the Thread.Sleep(0)?It is used to signal to Windows that.
- 8What is the difference between foreground and background threads?The foreground threads are used to keep the application alive, the application is terminated when it only has background threads.
- 9How to set a thread as background or foreground?Simply set the Thread.IsBackground to true/false.
- 10How to stop a thread?It can be used the Thread.Abort method. But it's called by another thread and it can happen at any time. When it happens, a ThreadAbortException is thrown, it may leave the application in an invalid state. A better way of doing that is to signal the target using a variable shared by the calling and target threads.
- 11What does the ThreadStatic attribute stand for?It's used to define a property as not a local variable. The thread owns the data on the field.
- 12What does the ThreadPool class stand for?It's a static class that provides a pool of threads that can used to execute tasks, post work items, process assynchronous IO, wait on behalf other threads, and process timers.
- 13How to you add a request for execution on a ThreadPool?Calling the ThreadPool.QueueWorkItem
- 14How the ThreadPool works?it pre-creates a number of threads that will be available when a new task is created.
- 15Why does Threadpool have MinThreads and MaxThreads?MinThreads - Defines the minimum number of threads pre-created
MaxThreads - The maximum number of threads created by the pool. - 16How to enqueue a work item on the ThreadPool?You have to call ThreadPool.QueueWorkItem()
passing the WaitCallback object with a method that you want to enqueue. - 17What are the difference between the threads created on the ThreadPool and Thread?1. All the threads on the thread pool are background
2. You can't abort a thread on the ThreadPool
3. You cannot join the threads on the ThreadPool
4. Threads on the ThreadPpool are reused
5. You can't control the priority on ThreadPool - 18What is a multi-threaded race condition?It's when two or more threads compete for the usage of a resource.
- 19What are the alternatives for the ThreadPool?TPL - Task Parallel Library
APM - Assynchronous Pattern Model
EAP - Event-based Assynchronous Pattern
TAP - Task-based Assynchronous Pattern
Async/Await - keywords - 20Why Task is better then thread pool?The Task class provides more flexibility and control over how the task/thread is created
- 21How do you create Task?1: Create an instace of a task
2: Call the TaskFactory.StartNew
3: Call the TaskFactory.Run
4: You can call one of the continuation methods Task.WhenAll, Task.WhenAny, TaskFactory.ContinueWhenAll and TaskFactory.ContinueWhenAny
(Task.Factory = TaskFactory) - 22What is the difference between WaitAll and WhenAll?WhenAll process tasks as a collection.
- 23What does the EventWaitHandle stand for?It represents a thread syncronization event.
- 24How do I instantiate a EventWaitHandler?When creating you must defining at minimum if the event should be signaled and if the event should reset manually or automatically.
Información
- Descripción
- Fichas sobre Threads, creado por Thiago Avelino el 17/01/2016.
- Creado por
- Thiago Avelino
- Visitas
- 0
- Valoración