From: Stephen Toub Date: Sun, 8 Jan 2017 18:25:17 +0000 (-0500) Subject: Remove lazy initialization of Task.CompletedTask (dotnet/coreclr#8846) X-Git-Tag: submit/tizen/20210909.063632~11030^2~8497 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d517c0bc3855676c6c7a7dd52a320cc069e5d123;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove lazy initialization of Task.CompletedTask (dotnet/coreclr#8846) Remove lazy initialization of Task.CompletedTask Commit migrated from https://github.com/dotnet/coreclr/commit/c58686343b1ff49473df8c962ff30eb91025a179 --- diff --git a/src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs b/src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs index 24a57fa..b385f06 100644 --- a/src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs +++ b/src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs @@ -147,7 +147,6 @@ namespace System.Threading.Tasks private static StackGuard t_stackGuard; // The stack guard object for this thread internal static int s_taskIdCounter; //static counter used to generate unique task IDs - private readonly static TaskFactory s_factory = new TaskFactory(); private volatile int m_taskId; // this task's unique ID. initialized only if it is ever requested @@ -1615,23 +1614,10 @@ namespace System.Threading.Tasks /// of , as would result from using /// the default constructor on TaskFactory. /// - public static TaskFactory Factory { get { return s_factory; } } - - /// A task that's already been completed successfully. - private static Task s_completedTask; + public static TaskFactory Factory { get; } = new TaskFactory(); /// Gets a task that's already been completed successfully. - /// May not always return the same instance. - public static Task CompletedTask - { - get - { - var completedTask = s_completedTask; - if (completedTask == null) - s_completedTask = completedTask = new Task(false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default(CancellationToken)); // benign initialization race condition - return completedTask; - } - } + public static Task CompletedTask { get; } = new Task(false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default(CancellationToken)); /// /// Provides an event that can be used to wait for completion.