8000 Fix some threading docs by kouvel · Pull Request #4961 · dotnet/dotnet-api-docs · GitHub
[go: up one dir, main page]

Skip to content

Fix some threading docs #4961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 27, 2020
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 @@ -50,7 +50,7 @@ private static void GenerateNumbers()
midpt++;
}
total++;
} while (midpointCount > 0);
} while (Volatile.Read(ref midpointCount) > 0);

Interlocked.Add(ref totalCount, total);
Interlocked.Add(ref totalMidpoint, midpt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static async Task Main()
midpt++;
}
total++;
} while (midpointCount > 0 );
} while (Volatile.Read(ref midpointCount) > 0);

Interlocked.Add(ref totalCount, total);
Interlocked.Add(ref totalMidpoint, midpt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static void GenerateNumbers()
midpt++;
}
total++;
} while (midpointCount < 10000);
} while (Volatile.Read(ref midpointCount) < 10000);

Interlocked.Add(ref totalCount, total);
Interlocked.Add(ref totalMidpoint, midpt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void Main()
midpt++;
}
total++;
} while (midpointCount < 50000);
} while (Volatile.Read(ref midpointCount) < 50000);

Interlocked.Add(ref totalCount, total);
Interlocked.Add(ref totalMidpoint, midpt);
Expand Down
198 changes: 147 additions & 51 deletions xml/System.Threading/EventWaitHandle.xml

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions xml/System.Threading/EventWaitHandleAcl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<param name="initialState">
<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>
<param name="mode">One of the enum values that determines whether the event resets automatically or manually.</param>
<param name="name">The name, if the event is to be shared with other processes; otherwise, <see langword="null" /> or an empty string.</param>
<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>
<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>
<param name="eventSecurity">The optional Windows access control security to apply.</param>
<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>
Expand All @@ -53,20 +53,29 @@
<format type="text/markdown"><![CDATA[

## Remarks
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).

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.
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.

]]></format>
</remarks>
<exception cref="T:System.ArgumentException">.NET Framework only: The <paramref name="name" /> length is beyond MAX_PATH (260 characters).
<exception cref="T:System.ArgumentException">
The <paramref name="mode" /> enum value was out of legal range.

-or-

.NET Framework only: The <paramref name="mode" /> enum value was out of legal range.</exception>
<exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="mode" /> enum value was out of legal range.</exception>
<exception cref="T:System.IO.DirectoryNotFoundException">Could not find a part of the path specified in <paramref name="name" />.</exception>
<exception cref="T:System.Threading.WaitHandleCannotBeOpenedException">A system-wide synchronization event with the provided <paramref name="name" /> was not found.
-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>
.NET Framework only: <paramref name="name" /> is longer than MAX_PATH (260 characters).</exception>
<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>
<exception cref="T:System.IO.IOException">
<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.

-or-

There was some other error. The `HResult` property may provide more information.</exception>
<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>
<exception cref="T:System.IO.PathTooLongException">The <paramref name="name" /> is too long. Length restrictions may depend on the operating system or configuration.</exception>
<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>
<exception cref="T:System.UnauthorizedAccessException">The named event exists, but the user does not have the desired security access.</exception>
</Docs>
</Member>
</Members>
Expand Down
11 changes: 7 additions & 4 deletions xml/System.Threading/ExecutionContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
<format type="text/markdown"><![CDATA[

## Remarks
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.
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/).

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.


- The following is applicable to .NET Framework only. -

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.

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>.
Expand Down Expand Up @@ -281,7 +283,7 @@
<format type="text/markdown"><![CDATA[

## Remarks
<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.
.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.

For more information, see <xref:System.Runtime.Serialization.SerializationInfo>.

Expand Down Expand Up @@ -370,6 +372,7 @@ To revert to the current execution context; capture it before calling Restore, a

]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException"><paramref name="executionContext" /> is <see langword="null"/>.</exception>
</Docs>
</Member>
<Member MemberName="RestoreFlow">
Expand Down Expand Up @@ -474,7 +477,7 @@ To revert to the current execution context; capture it before calling Restore, a
<format type="text/markdown"><![CDATA[

## Remarks
The execution context is returned to its previous state when the method completes.
The execution context and synchronization contexts of the calling thread are returned to their previous states when the method completes.

]]></format>
</remarks>
Expand Down
Loading
0