Consider the following pseudocode.
{
Task.Factory.StartNew(() => process(1));
Task.Factory.StartNew(() => process(2));
Task.Factory.StartNew(() => process(3));
Task.Factory.StartNew(() => process(4));
}
private ReaderWriterLockSlim theLock = new ReaderWriterLockSlim();
private List<int> theLock = new List <int> ();
private process(int input)
{
theLock .enterwritelock();
//some complicated process, which takes approximately 10 seconds
container.add(input);
theLock.exitwritelock();
}
Now, am I guaranteed to find the contents of 'container' as follows,
container contents:
1
2
3
4
...or could I possibly get a different order?
I ask this, because I want to do a series of tasks, but I need to know how ReaderWriteLockSlim works: ie. does it queue tasks according to the order they came in, or is possible for a newer task to be processed before an older task, which entered the queue earlier.
Thanks
{
Task.Factory.StartNew(() => process(1));
Task.Factory.StartNew(() => process(2));
Task.Factory.StartNew(() => process(3));
Task.Factory.StartNew(() => process(4));
}
private ReaderWriterLockSlim theLock = new ReaderWriterLockSlim();
private List<int> theLock = new List <int> ();
private process(int input)
{
theLock .enterwritelock();
//some complicated process, which takes approximately 10 seconds
container.add(input);
theLock.exitwritelock();
}
Now, am I guaranteed to find the contents of 'container' as follows,
container contents:
1
2
3
4
...or could I possibly get a different order?
I ask this, because I want to do a series of tasks, but I need to know how ReaderWriteLockSlim works: ie. does it queue tasks according to the order they came in, or is possible for a newer task to be processed before an older task, which entered the queue earlier.
Thanks