http://http://www.c-sharpcorner.com/Forumnew links/Thread/142312/threading.aspx
What is your definition of Synchronization?
Can you point out some weird issues when dealing with Thread Synchronization? In my past experience. I experience a lot timing issues etc.....
Well my definition is to ensure that your sets are completely processed before you gets happen. These issues happens when you have threaded methods that are not Asynchronus methods. This is were locks and semaphores comes into place.
Loading
VulpesPosted Oct 5, 2011, 2:01 PM
David SmithPosted Oct 5, 2011, 1:37 PM
I was doing some reading on locks from the article below. Does the lock become released after the parent method or thread has returned?
Creating mutually exclusive code block C#
Sometimes, we may need to act on some information(object) which is critical for the application and we need to make sure that the information contained by that object is consistent. The way to keep the information in the object consistent is to avoid the access of that object by more than one thread or program. In short, we need to achieve mutual exclusion for that object for predefined number of statements or block of code. C# offers this by several ways such as lock, mutex and semaphores. lock statement is the easiest way to lock the object and the related statements.
The basic syntax is below.
Object thisLock = new Object();
lock (thisLock)
{
// Critical code section
}
Suppose you act upon one DataTable object and you do not want to alter the content of it by more than one threads then option available is to lock that datatable object.
DataTable dt = DatabaseOperations.GetDataTable(SQL);
lock(dt)
{
// critical statements to alter the contents inside dt
}
In short, lock enables us to achieve the mutually exclusive access to the locked object such that, when it is locked, no other thread can access that locked object until its lock is released. The thread that attempts to gain the access of the locked object gets to the SUPENDED state until the lock is removed.
Examples
lock(this) – locks the current instance of the object in which the statements are being executed.
lock(typeof(ClassName)) – locks the static members of the class ClassName
Sam HobbsPosted Oct 5, 2011, 1:05 PM
Let's say that you and a friend Jasmine want to meet for dinner, but you and she will be in meetings and otehr things so you are not sure when. So you call her and she calls you and you agree whan and where to meet. You and she might also use text messages so you are able to communicate during a meeting. So you are on the way to meet Jasmine and you get trapped by a dust storm. So you call her and say you have to postpone or cancel dinner. So for that, the phone is a synchronization object; you might say that it provides two synchronization objects, voice and text.
VulpesPosted Oct 5, 2011, 6:14 AM
All objects are stored on the heap and included in the overhead (8 bytes on a 32-bit system) they all have is a 'sync block address' which is a pointer into a system-wide tables of structures used for synchronization. If this pointer is not NULL, then the object is currently locked.