8000 Fix some threading docs (#4961) · dotnet/dotnet-api-docs@492ee8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 492ee8c

Browse files
authored
Fix some threading docs (#4961)
* Add exception case for ExecutionContext.Restore * Improve docs for named wait handles * Small update to samples for interlocked decrement/increment * Update some ExecutionContext docs for .NET Core * Sempahore's OpenExisting and TryOpenExisting do not throw DirectoryNotFoundException * OpenExisting may throw WaitHandleCannotBeOpenedException or TryOpenExisting may return false for invalid names in some cases
1 parent f155af7 commit 492ee8c

File tree

11 files changed

+479
-184
lines changed

11 files changed

+479
-184
lines changed

samples/snippets/csharp/VS_Snippets_CLR_System/system.threading.interlocked.decrement/cs/decrement1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private static void GenerateNumbers()
5050
midpt++;
5151
}
5252
total++;
53-
} while (midpointCount > 0);
53+
} while (Volatile.Read(ref midpointCount) > 0);
5454

5555
Interlocked.Add(ref totalCount, total);
5656
Interlocked.Add(ref totalMidpoint, midpt);

samples/snippets/csharp/VS_Snippets_CLR_System/system.threading.interlocked.decrement/cs/decrement2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static async Task Main()
3636
midpt++;
3737
}
3838
total++;
39-
} while (midpointCount > 0 );
39+
} while (Volatile.Read(ref midpointCount) > 0);
4040

4141
Interlocked.Add(ref totalCount, total);
4242
Interlocked.Add(ref totalMidpoint, midpt);

samples/snippets/csharp/VS_Snippets_CLR_System/system.threading.interlocked.increment2/cs/increment3.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private static void GenerateNumbers()
5050
midpt++;
5151
}
5252
total++;
53-
} while (midpointCount < 10000);
53+
} while (Volatile.Read(ref midpointCount) < 10000);
5454

5555
Interlocked.Add(ref totalCount, total);
5656
Interlocked.Add(ref totalMidpoint, midpt);

samples/snippets/csharp/VS_Snippets_CLR_System/system.threading.interlocked.increment2/cs/increment4.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void Main()
3535
midpt++;
3636
}
3737
total++;
38-
} while (midpointCount < 50000);
38+
} while (Volatile.Read(ref midpointCount) < 50000);
3939

4040
Interlocked.Add(ref totalCount, total);
4141
Interlocked.Add(ref totalMidpoint, midpt);

xml/System.Threading/EventWaitHandle.xml

Lines changed: 147 additions & 51 deletions
Large diffs are not rendered by default.

xml/System.Threading/EventWaitHandleAcl.xml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<param name="initialState">
4545
<see langword="true" /> to set the initial state to signaled if the named event is created as a result of this call; <see langword="false" /> to set it to non-signaled.</param>
4646
<param name="mode">One of the enum values that determines whether the event resets automatically or manually.</param>
47-
<param name="name">The name, if the event is to be shared with other processes; otherwise, <see langword="null" /> or an empty string.</param>
47+
<param name="name">The name, if the synchronization object is to be shared with other processes; otherwise, <see langword="null" /> or an empty string. The name is case-sensitive.</param>
4848
<param name="createdNew">When this method returns, this argument is always set to <see langword="true" /> if a local event is created; that is, when <paramref name="name" /> is <see langword="null" /> or <see cref="F:System.String.Empty" />. If <paramref name="name" /> has a valid, non-empty value, this argument is set to <see langword="true" /> when the system event is created, or it is set to <see langword="false" /> if an existing system event is found with that name.</param>
4949
<param name="eventSecurity">The optional Windows access control security to apply.</param>
5050
<summary>Gets or creates an <see cref="T:System.Threading.EventWaitHandle" /> instance, allowing a <see cref="T:System.Security.AccessControl.EventWaitHandleSecurity" /> instance to be optionally specified to set it during the event creation.</summary>
@@ -53,20 +53,29 @@
5353
<format type="text/markdown"><![CDATA[
5454
5555
## Remarks
56+
The `name` may be prefixed with `Global\` or `Local\` to specify a namespace. When the `Global` namespace is specified, the synchronization object may be shared with any processes on the system. When the `Local` namespace is specified, which is also the default when no namespace is specified, the synchronization object may be shared with processes in the same session. On Windows, a session is a login session, and services typically run in a different non-interactive session. On Unix-like operating systems, each shell has its own session. Session-local synchronization objects may be appropriate for synchronizing between processes with a parent/child relationship where they all run in the same session. For more information about synchornization object names on Windows, see [Object Names](https://docs.microsoft.com/windows/win32/sync/object-names).
5657
57-
If a `name` is passed and the system event already exists, the existing event is returned. If `name` is `null` or <xref:System.String.Empty>, a new process-local event is created.
58+
If a `name` is provided and a synchronization object of the requested type already exists in the namespace, the existing synchronization object is opened. If a synchronization object of a different type already exists in the namespace, a `WaitHandleCannotBeOpenedException` is thrown. Otherwise, a new synchronization object is created.
5859
5960
]]></format>
6061
</remarks>
61-
<exception cref="T:System.ArgumentException">.NET Framework only: The <paramref name="name" /> length is beyond MAX_PATH (260 characters).
62+
<exception cref="T:System.ArgumentException">
63+
The <paramref name="mode" /> enum value was out of legal range.
6264

6365
-or-
6466

65-
.NET Framework only: The <paramref name="mode" /> enum value was out of legal range.</exception>
66-
<exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="mode" /> enum value was out of legal range.</exception>
67-
<exception cref="T:System.IO.DirectoryNotFoundException">Could not find a part of the path specified in <paramref name="name" />.</exception>
68-
<exception cref="T:System.Threading.WaitHandleCannotBeOpenedException">A system-wide synchronization event with the provided <paramref name="name" /> was not found.
69-
-or- An <see cref="T:System.Threading.EventWaitHandle" /> with system-wide name <paramref name="name" /> cannot be created. An <see cref="T:System.Threading.EventWaitHandle" /> of a different type might have the same name.</exception>
67+
.NET Framework only: <paramref name="name" /> is longer than MAX_PATH (260 characters).</exception>
68+
<exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="mode" /> enum value was out of legal range. In some cases <see cref="T:System.ArgumentException"/> is thrown instead.</exception>
69+
<exception cref="T:System.IO.IOException">
70+
<paramref name="name" /> is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local\" are case-sensitive.
71+
72+
-or-
73+
74+
There was some other error. The `HResult` property may provide more information.</exception>
75+
<exception cref="T:System.IO.DirectoryNotFoundException">Windows only: <paramref name="name" /> specified an unknown namespace. See [Object Names](https://docs.microsoft.com/windows/win32/sync/object-names) for more information.</exception>
76+
<exception cref="T:System.IO.PathTooLongException">The <paramref name="name" /> is too long. Length restrictions may depend on the operating system or configuration.</exception>
77+
<exception cref="T:System.Threading.WaitHandleCannotBeOpenedException">A synchronization object with the provided <paramref name="name" /> cannot be created. A synchronization object of a different type might have the same name.</exception>
78+
<exception cref="T:System.UnauthorizedAccessException">The named event exists, but the user does not have the desired security access.</exception>
7079
</Docs>
7180
</Member>
7281
</Members>

xml/System.Threading/ExecutionContext.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@
6161
<format type="text/markdown"><![CDATA[
6262
6363
## Remarks
64-
The <xref:System.Threading.ExecutionContext> class provides a single container for all information relevant to a logical thread of execution. This includes security context, call context, and synchronization context.
64+
The <xref:System.Threading.ExecutionContext> class provides a single container for all information relevant to a logical thread of execution. In .NET Framework, this includes security context, call context, and synchronization context. In .NET Core, the security context and call context are not supported, however, the impersonation context and culture would typically flow with the execution context. Also in .NET Core, the synchronization context does not flow with the execution context, whereas in .NET Framework it may in some cases. For more information, see [ExecutionContext vs SynchronizationContext](https://devblogs.microsoft.com/pfxteam/executioncontext-vs-synchronizationcontext/).
6565
6666
The <xref:System.Threading.ExecutionContext> class provides the functionality for user code to capture and transfer this context across user-defined asynchronous points. The common language runtime ensures that the <xref:System.Threading.ExecutionContext> is consistently transferred across runtime-defined asynchronous points within the managed process.
67-
67+
68+
- The following is applicable to .NET Framework only. -
69+
6870
An execution context is the managed equivalent of a COM apartment. Within an application domain, the entire execution context must be transferred whenever a thread is transferred. This situation occurs during transfers made by the <xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType> method, most thread pool operations, and Windows Forms thread marshaling through the Windows message pump. It does not occur in unsafe thread pool operations (such as the <xref:System.Threading.ThreadPool.UnsafeQueueUserWorkItem%2A> method), which do not transfer the compressed stack. Wherever the compressed stack flows, the managed principal, synchronization, locale, and user context also flow. The <xref:System.Threading.ExecutionContext> class provides the <xref:System.Threading.ExecutionContext.Capture%2A> and <xref:System.Threading.ExecutionContext.CreateCopy%2A> methods to get the execution context and the <xref:System.Threading.ExecutionContext.Run%2A> method to set the execution context for the current thread.
6971
7072
An <xref:System.Threading.ExecutionContext> that is associated with a thread cannot be set on another thread. Attempting to do so will result in an exception being thrown. To propagate the <xref:System.Threading.ExecutionContext> from one thread to another, make a copy of the <xref:System.Threading.ExecutionContext>.
@@ -281,7 +283,7 @@
281283
<format type="text/markdown"><![CDATA[
282284
283285
## Remarks
284-
<xref:System.Threading.ExecutionContext.GetObjectData%2A> sets a <xref:System.Runtime.Serialization.SerializationInfo> with the logical call context information. During deserialization, the execution context object is reconstituted from the <xref:System.Runtime.Serialization.SerializationInfo> transmitted over the stream.
286+
.NET Framework only: <xref:System.Threading.ExecutionContext.GetObjectData%2A> sets a <xref:System.Runtime.Serialization.SerializationInfo> with the logical call context information. During deserialization, the execution context object is reconstituted from the <xref:System.Runtime.Serialization.SerializationInfo> transmitted over the stream.
285287
286288
For more information, see <xref:System.Runtime.Serialization.SerializationInfo>.
287289
@@ -370,6 +372,7 @@ To revert to the current execution context; capture it before calling Restore, a
370372
371373
]]></format>
372374
</remarks>
375+
<exception cref="T:System.InvalidOperationException"><paramref name="executionContext" /> is <see langword="null"/>.</exception>
373376
</Docs>
374377
</Member>
375378
<Member MemberName="RestoreFlow">
@@ -474,7 +477,7 @@ To revert to the current execution context; capture it before calling Restore, a
474477
<format type="text/markdown"><![CDATA[
475478
476479
## Remarks
477-
The execution context is returned to its previous state when the method completes.
480+
The execution context and synchronization contexts of the calling thread are returned to their previous states when the method completes.
478481
479482
]]></format>
480483
</remarks>

0 commit comments

Comments
 (0)
0