Hi Guys
NP101 Synchronized()
http://www.java2s.com/Tutorial/CSharp/0220__Data-Structure/Getthenumberofelements.htm
Following incomplete program is given in the above website. This program is intended to explain Synchronized(); method. Please complete the program.
Thank you
using System;
using System.Collections;
class MainClass
{
static void
{
ArrayList a = new ArrayList(10);
ArrayList.Synchronized(a);
}
}
Posted Aug 2, 2008, 8:11 PM
I am not conversant with threads in C#. After studying threads I will try to understand the explanation. Thank you for your attempt.
AlanPosted Aug 2, 2008, 7:41 PM
An ArrayList isn't threadsafe which can lead to unpredictable behaviour if two or more threads attempt to access it simultaneously.
To prevent this behaviour, the ArrayList.Synchronized() method can be called to create a threadsafe wrapper for the ArrayList which should then be used in multithreaded scenarios.
Because the sort of threading problems which the Synchronized() method prevents tend to be intermittent, it's difficult to actually come up with an example where it (reliably) makes a difference and this is probably why the author of the example code didn't bother to add anything to it.