Skip to content
Draft
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
6 changes: 3 additions & 3 deletions standard/conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
> ```csharp
> enum Color { Red, Blue, Green }
>
> // The expression 0 converts implicitly to enum types

Check warning on line 28 in standard/conversions.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/conversions.md#L28

MDC032::Line length 82 > maximum 81
> Color c0 = 0;
>
> // Other int expressions need explicit conversion
Expand Down Expand Up @@ -166,9 +166,9 @@
The implicit reference conversions are:

- A null literal conversion ([§10.2.7](conversions.md#1027-null-literal-conversions)) to any *reference_type*.
- From any *reference_type* to `object` and `dynamic`.
- From any *class_type* `S` to any *class_type* `T`, provided `S` is derived from `T`.
- From any *class_type* `S` to any *interface_type* `T`, provided `S` implements `T`.
- From any *reference_type* to `object` and `dynamic`. A warning shall be issued when *reference_type* is `System.Threading.Lock`.
- From any *class_type* `S` to any *class_type* `T`, provided `S` is derived from `T`. A warning shall be issued when `S` is `System.Threading.Lock`.
- From any *class_type* `S` to any *interface_type* `T`, provided `S` implements `T`. A warning shall be issued when `S` is `System.Threading.Lock`.
- From any *interface_type* `S` to any *interface_type* `T`, provided `S` is derived from `T`.
- From an *array_type* `S` with an element type `Sᵢ` to an *array_type* `T` with an element type `Tᵢ`, provided all of the following are true:
- `S` and `T` differ only in element type. In other words, `S` and `T` have the same number of dimensions.
Expand Down
12 changes: 12 additions & 0 deletions standard/standard-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,16 @@ namespace System.Threading
{
public bool IsCancellationRequested { get; }
}

public sealed class Lock
{
public Lock();
public System.Threading.Lock.Scope EnterScope();
public ref struct Lock.Scope
{
public void Dispose();
}
}
}

namespace System.Threading.Tasks
Expand Down Expand Up @@ -1564,6 +1574,8 @@ The following library types are referenced in this specification. The full names
- `global::System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>`
- `global::System.Runtime.CompilerServices.Unsafe`
- `global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute`
- `global::System.Threading.Lock`
- `global::System.Threading.Lock.Scope`
- `global::System.Threading.Monitor`
- `global::System.Threading.Tasks.Task`
- `global::System.Threading.Tasks.Task<TResult>`
Expand Down
19 changes: 18 additions & 1 deletion standard/statements.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 13 Statements

## 13.1 General

Check warning on line 3 in standard/statements.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/statements.md#L3

MDC032::Line length 90 > maximum 81

C# provides a variety of statements.

Check warning on line 6 in standard/statements.md

View workflow job for this annotation

GitHub Actions / Markdown to Word Converter

standard/statements.md#L6

MDC032::Line length 98 > maximum 81
> *Note*: Most of these statements will be familiar to developers who have programmed in C and C++. *end note*

```ANTLR
Expand Down Expand Up @@ -2027,7 +2027,7 @@

`lock (x)` …

where `x` is an expression of a *reference_type*, is precisely equivalent to:
where `x` is an expression of a *reference_type* other than `System.Threading.Lock`, is precisely equivalent to:

```csharp
bool __lockWasTaken = false;
Expand All @@ -2047,8 +2047,25 @@

except that `x` is only evaluated once.

A `lock` statement of the form

`lock (x)` …

where `x` is an expression of type `System.Threading.Lock`, is precisely equivalent to:

```csharp
using (x.EnterScope())
{
…
}
```

Note carefully that when `x` is an expression of type `System.Threading.Lock`, the statements `lock (x) …` and `lock ((object)x) …` are treated quite differently. The former uses the `Lock`/`Scope` approach described above while the latter uses the `Monitor.Enter`/`Exit` approach described earlier, as the expression does not have type `System.Threading.Lock` in the latter case, and a warning to that effect is reported.

While a mutual-exclusion lock is held, code executing in the same execution thread can also obtain and release the lock. However, code executing in other threads is blocked from obtaining the lock until the lock is released.

It is a compile-time error to use a lock statement on a value of type 'System.Threading.Lock' in an async method or async lambda expression.

## 13.14 The using statement

### 13.14.1 General
Expand Down
Loading