Skip to content

Use bools and enums with Interlocked.CompareExchange #3686

@jamescrosswell

Description

@jamescrosswell

In various places in the solution we're using int instead of bool so that we can make use of the Interlocked class, which historically did not support bool and enum. For example:

internal static bool ThrowOnNextStartupForTests
{
get { return Interlocked.CompareExchange(ref _throwOnNextStartupForTests, 1, 1) == 1; }
set
{
if (value)
Interlocked.CompareExchange(ref _throwOnNextStartupForTests, 1, 0);
else
Interlocked.CompareExchange(ref _throwOnNextStartupForTests, 0, 1);
}
}

With .net9 Interlocked.CompareExchange supports more types.

We should leverage the new type support to tidy up our code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeGood First IssueGood for newcomersTask

    Projects

    Status

    Done

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions