Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
2 changes: 1 addition & 1 deletion mcs/class/corlib/System.Threading/ThreadLocal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DataSlotWrapper
public Func<T> Getter;
}

public ThreadLocal () : this (LazyInitializer.GetDefaultCtorValue<T>)
public ThreadLocal () : this (()=> default(T))
{
}

Expand Down
18 changes: 18 additions & 0 deletions mcs/class/corlib/Test/System.Threading/ThreadLocalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

using System;
using System.Threading;
using System.Collections;

using NUnit;
using NUnit.Core;
Expand Down Expand Up @@ -61,8 +62,19 @@ public void ThreadedTest ()
Thread t = new Thread ((object o) => { Interlocked.Decrement (ref nTimes); AssertThreadLocal (); });
t.Start ();
t.Join ();

}


[Test]
public void DefaultValueIsUsedIfNoneSupplied()
{
ThreadLocal<IEnumerable> local = new ThreadLocal<IEnumerable>();
IEnumerable value = local.Value;
Assert.AreEqual(null, value);
}


[Test]
public void InitializeThrowingTest ()
{
Expand Down Expand Up @@ -114,6 +126,12 @@ void AssertThreadLocal ()
Assert.AreEqual (42, threadLocal.Value, "#4");
Assert.AreEqual (1, nTimes, "#5");
}

}

}




#endif