Showing posts with label Interlocked. Show all posts
Showing posts with label Interlocked. Show all posts

Sunday, 1 January 2012

DotNet Frequently Asked Questions on Threading - 2

What are Daemon threads and how can a thread be created as Daemon?


Daemon thread's run in background and stop automatically when nothing is running program. Example of a Daemon thread is "Garbage collector". Garbage collector runs until some .NET code is running or else its idle.
You can make a thread Daemon by
Thread.Isbackground=true

When working with shared data in threading how do you implement synchronization ?


There are certain situtations that you need to be careful with when using threads. If two threads (e.g. the main and any worker threads) try to access the same variable at the same time, you'll have a problem. This can be very difficult to debug because they may not always do it at exactly the same time. To avoid the problem, you can