Managed Vs Unmanaged Threads (CLR Thread vs Windows Threads)Managed threads are created by CLR. As of now there is one -one mapping in between CLR thread and windows thread but in future this may change and CLR may introduce logical threading. In order to access windows thread we need to directly call WIn32 APIs via PInvoke that should be avoided as much as possible. Dedicated Threads Vs Thread Pool Vs Timer
When to Use Background Worker ThreadWhen we need to know the progress of any background operation. It has built in support progress update The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution. To execute a time-consuming operation in the background, create a BackgroundWorker and listen for events that report the progress of your operation and signal when your operation is finished. You can create the BackgroundWorker programmatically or you can drag it onto your form from the Components tab of the Toolbox. If you create the BackgroundWorker in the Windows Forms Designer, it will appear in the Component Tray, and its properties will be displayed in the Properties window. When to use Thread Pool
Background worker Vs Thread Pool
Limitations of Thread Pool
User Mode Scheduling (UMS) VsFiberUMS threads differ from fibers in that each UMS thread has its own thread context instead of sharing the thread context of a single thread. When to suppress execution context flow.Execution context is a data structure that is passed from parent to child thread and it have significant overhead, by suppressing context overflow we can gain performance in server application, however we should do only when if code that will be executed by thread is not using any such information that execution context provide such as uername of access rights. Live Lock Vs Dead LockIf the system is in dead-lock and only user mode construct are used the it is called live lock because user mode locks are implemented using spin wait that burn CPU cycle white. The same situation will be called Dead-Lock if kernel mode constructs are used because they do not waste CPU cycle. Kernel Vs User Mode SynchronizationUser Mode : Light weight but burn CPU cycle, Kernel mode: Expensive to create but saved CPU cycles and Context Switching What is the purpose of “ Control.InvokeRequired”
Because controls are always owned by the UI thread, it is generally unsafe to make calls to controls from a different thread. You can use the Control.InvokeRequired property to determine if it is safe to make a call to a control from another thread. If Invoke-Required returns False, it is safe to make the call to the control. If InvokeRequired returns True, however, you should use the Control.Invoke method on the owning form to supply a delegate to a method to access the control. Using Control.Invoke allows the control to be accessed in a thread-safe manner. When to use thread PoolAlways prefer using a ThreadPool thread. It is efficient and helps avoid the overhead associated with creating, starting, and stopping threads. Avoid using the ThreadPool if...
When to explicitly use thread classWhat is default size of dot net thread pool25 per processor, 1024 on Windows 7List the possible use of threads in developing a thick client server application.
Background worker Vs Thread Pool
How to know that the progress of operation running under thread pool?Thread pool itself do not provide any such construct so we need to use Asynchronous Programming Model. How to periodically call an asynchronous operation?Best way is to use
Threading.Timer Class that actually pushes the task in to application thread
pool. Limitations of Thread Pool
UnsafeQueueUserWorkitem Vs QueueUserWorkitem
What is the purpose of Thread.Interrupt ?
What is the Solution to cache coherency problemUse Volatile R/W or volatile keyword. What are the limitations of Interlocked Methods?They are very few in numbers and work only on Int32. Monitor Vs Lock StatementsLock implicitly implements Monitor.Enter and Monitor.Leave What is the best Implementation while using lock statement?Always use private locking object. What is ReaderWriterLockIt defines a lock that supports single writers and multiple readers. http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlock.aspx When to Use Kernel Locking Construct
How does recursion impact synchronization mechanismA recursive lock is a variant on the mutex lock. A recursive lock allows a single thread to acquire the lock multiple times before releasing it. Other threads remain blocked until the owner of the lock releases the lock the same number of times it acquired it. Recursive locks are used during recursive iterations primarily but may also be used in cases where multiple methods each need to acquire the lock separately. Locks that support recursion such as ReaderWriterLock and Monitor do not support this programming architecture. Manual Vs Auto Reset Event
Event Vs Mutex
Live Lock Vs Dead LockWhen thread are blocked at CRL Synchronization Construct
then it is called Live Lock and on the other hand when it is blocked on kernel
synchronization construct them it is called dead lock. What is wait handle?
Does Lock Keyword work on value typeNo because lock actually uses sync block that re implemented by heap only. Also it is not really required because value types are always passed by copying so multiple threads have different copies of same value object. |