Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void TestBasicScenarios()
Task[] tks = new Task[2];
// A simple blocking consumer with no cancellation.
int expect = 1;
tks[0] = Task.Factory.StartNew(() =>
tks[0] = Task.Run(() =>
{
while (!bc.IsCompleted)
{
Expand All @@ -34,17 +34,17 @@ public static void TestBasicScenarios()
}
catch (InvalidOperationException) { } // throw when CompleteAdding called
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

// A simple blocking producer with no cancellation.
tks[1] = Task.Factory.StartNew(() =>
tks[1] = Task.Run(() =>
{
bc.Add(1);
bc.Add(2);
bc.Add(3);
// Let consumer know we are done.
bc.CompleteAdding();
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

Task.WaitAll(tks);
}
Expand Down Expand Up @@ -161,10 +161,10 @@ public static void TestBugFix914998()

producer2.CompleteAdding();

Task.Factory.StartNew(() =>
Task.Run(() =>
{
producer1.Add(100);
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

int ignored, index, timeout = 5000;
index = BlockingCollection<int>.TryTakeFromAny(producerArray, out ignored, timeout);
Expand Down
12 changes: 6 additions & 6 deletions src/System.Collections.Concurrent/tests/ConcurrentBagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public static void TestBasicScenarios()
{
ConcurrentBag<int> cb = new ConcurrentBag<int>();
Task[] tks = new Task[2];
tks[0] = Task.Factory.StartNew(() =>
tks[0] = Task.Run(() =>
{
cb.Add(4);
cb.Add(5);
cb.Add(6);
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

// Consume the items in the bag
tks[1] = Task.Factory.StartNew(() =>
tks[1] = Task.Run(() =>
{
int item;
while (!cb.IsEmpty)
Expand All @@ -40,7 +40,7 @@ public static void TestBasicScenarios()
Assert.False(true, "Expected: 4|5|6; actual: " + item.ToString());
}
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

Task.WaitAll(tks);
}
Expand Down Expand Up @@ -398,12 +398,12 @@ public static void RTest9_ToArray()
Task[] tasks = new Task[10];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
tasks[i] = Task.Run(() =>
{
int[] array = bag.ToArray();
if (array == null || array.Length != 10000)
Interlocked.Increment(ref failCount);
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});
}

Task.WaitAll(tasks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void TestBasicScenarios()
ConcurrentDictionary<int, int> cd = new ConcurrentDictionary<int, int>();

Task[] tks = new Task[2];
tks[0] = Task.Factory.StartNew(() =>
tks[0] = Task.Run(() =>
{
var ret = cd.TryAdd(1, 11);
if (!ret)
Expand All @@ -34,9 +34,9 @@ public static void TestBasicScenarios()
ret = cd.TryUpdate(2, 22, 222);
Assert.True(ret);
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

tks[1] = Task.Factory.StartNew(() =>
tks[1] = Task.Run(() =>
{
var ret = cd.TryAdd(2, 222);
if (!ret)
Expand All @@ -51,7 +51,7 @@ public static void TestBasicScenarios()
ret = cd.TryUpdate(1, 111, 11);
Assert.True(ret);
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

Task.WaitAll(tks);
}
Expand Down
28 changes: 12 additions & 16 deletions src/System.Collections.Concurrent/tests/ConcurrentQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public static void TestBasicScenarios()
cq.Enqueue(1);

Task[] tks = new Task[2];
tks[0] = Task.Factory.StartNew(() =>
tks[0] = Task.Run(() =>
{
cq.Enqueue(2);
cq.Enqueue(3);
cq.Enqueue(4);
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

tks[1] = Task.Factory.StartNew(() =>
tks[1] = Task.Run(() =>
{
int item1, item2;
var ret1 = cq.TryDequeue(out item1);
Expand All @@ -44,7 +44,7 @@ public static void TestBasicScenarios()
{
Assert.Equal(1, item1);
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

Task.WaitAll(tks);
}
Expand Down Expand Up @@ -138,8 +138,7 @@ public static void TestBugFix570046()
{
var q = new ConcurrentQueue<int?>();

var t1 = Task.Factory.StartNew(
() =>
var t1 = Task.Run(() =>
{
for (int i = 0; i < 1000000; i++)
{
Expand All @@ -148,16 +147,15 @@ public static void TestBugFix570046()

Assert.True(q.TryDequeue(out o), "TryDequeue should never return false in this test");
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

var t2 = Task.Factory.StartNew(
() =>
var t2 = Task.Run(() =>
{
foreach (var item in q)
{
Assert.NotNull(item);
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

t2.Wait();
}
Expand All @@ -171,13 +169,11 @@ public static void TestBugFix570046()
public static void TestBugFix484295()
{
CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(15));
Task<InvalidPeekException> peepTask = Task.Factory
.StartNew(() => TryPeek(cts.Token), cts.Token)
.ContinueWith(task => HandleExceptions(task));
Task<InvalidPeekException> peepTask = Task
.Run(() => TryPeek(cts.Token), cts.Token)
.ContinueWith(task => HandleExceptions(task), TaskScheduler.Default);

Task queueDequeueTask = Task.Factory.StartNew(
() => QueueDequeue(cts.Token),
cts.Token, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
Task queueDequeueTask = Task.Run(() => QueueDequeue(cts.Token));

Console.WriteLine("Waiting 15 seconds for both Queue/Dequeue and TryPeek tasks..");
Task.WaitAll(peepTask, queueDequeueTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public static void TestBasicScenarios()
cs.Push(1);

Task[] tks = new Task[2];
tks[0] = Task.Factory.StartNew(() =>
tks[0] = Task.Run(() =>
{
cs.Push(2);
cs.Push(3);
cs.Push(4);
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

tks[1] = Task.Factory.StartNew(() =>
tks[1] = Task.Run(() =>
{
int item1, item2;
var ret1 = cs.TryPop(out item1);
Expand All @@ -44,7 +44,7 @@ public static void TestBasicScenarios()
{
Assert.Equal(1, item1);
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
});

Task.WaitAll(tks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public Boolean runTest()
{
for (int i = 0; i < m_ThreadsToUse; i++)
{
ths[i] = Task.Factory.StartNew(new Action(this.StartEnThread), TaskCreationOptions.LongRunning);
ths[i] = Task.Factory.StartNew(new Action(this.StartEnThread), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
m_ThreadCount = m_ThreadsToUse;
Task.WaitAll(ths);
Expand Down Expand Up @@ -190,7 +190,7 @@ public Boolean runTest()
m_ThreadCount = m_ThreadsToUse;
for (int i = 0; i < m_ThreadsToUse; i++)
{
ths[i] = Task.Factory.StartNew(new Action(this.StartDeThread), TaskCreationOptions.LongRunning);
ths[i] = Task.Factory.StartNew(new Action(this.StartDeThread), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
Task.WaitAll(ths);

Expand Down Expand Up @@ -218,7 +218,7 @@ public Boolean runTest()
m_ThreadCount = m_ThreadsToUse;
for (int i = 0; i < m_ThreadsToUse; i++)
{
ths[i] = Task.Factory.StartNew(new Action(this.StartDeEnThread), TaskCreationOptions.LongRunning);
ths[i] = Task.Factory.StartNew(new Action(this.StartDeEnThread), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
Task.WaitAll(ths);

Expand All @@ -245,7 +245,7 @@ public Boolean runTest()
m_ThreadCount = m_ThreadsToUse;
for (int i = 0; i < m_ThreadsToUse; i++)
{
ths[i] = Task.Factory.StartNew(new Action(this.StartEnDeThread), TaskCreationOptions.LongRunning);
ths[i] = Task.Factory.StartNew(new Action(this.StartEnDeThread), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
Task.WaitAll(ths);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ public bool runTest()
iCountErrors++;
}

//we are going to rumble with the Queues with 2 threads

workers = new Task[iNumberOfWorkers];
ts1 = new Action(SortElements);
ts2 = new Action(ReverseElements);
for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2)
{
workers[iThreads] = Task.Factory.StartNew(ts1, TaskCreationOptions.LongRunning);
workers[iThreads + 1] = Task.Factory.StartNew(ts2, TaskCreationOptions.LongRunning);
workers[iThreads] = Task.Run(ts1);
workers[iThreads + 1] = Task.Run(ts2);
}

Task.WaitAll(workers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ public bool runTest()
Console.WriteLine("Err_234dnvf! Expected value not returned, " + (arrSon.SyncRoot == arrMother.SyncRoot));
}

//we are going to rumble with the Stacks with 2 threads
var ts1 = new Action(SortElements);
var ts2 = new Action(ReverseElements);
Task[] tasks = new Task[iNumberOfWorkers];
for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2)
{
tasks[iThreads] = Task.Factory.StartNew(ts1, TaskCreationOptions.LongRunning);
tasks[iThreads + 1] = Task.Factory.StartNew(ts2, TaskCreationOptions.LongRunning);
tasks[iThreads] = Task.Run(ts1);
tasks[iThreads + 1] = Task.Run(ts2);
}
Task.WaitAll(tasks);

Expand Down