Skip to content

Race condition in sample code #9012

Open
@ceciliachan1979

Description

@ceciliachan1979

Here we have the code like this:

semaphore.Release(3);
Console.WriteLine("{0} tasks can enter the semaphore.",
semaphore.CurrentCount);

Isn't that a race condition? It could happen that once the semaphore is released, the count can change right away by other threads?

Activity

ghost added
untriagedNew issue has not been triaged by the area owner
on May 16, 2023
svick

svick commented on May 16, 2023

@svick
Contributor

Is that a problem? That information is only used for logging, so I don't think it matters. And I also think the code required to make it accurate would be unnecessarily complicated.

ceciliachan1979

ceciliachan1979 commented on May 16, 2023

@ceciliachan1979
Author

Is that a problem? That information is only used for logging, so I don't think it matters. And I also think the code required to make it accurate would be unnecessarily complicated.

I think it is a bad idea to have wrong code there. I understand it can get complicated to make it accurate, how about not logging that at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.ThreadinguntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @svick@eiriktsarpalis@ceciliachan1979

        Issue actions

          Race condition in sample code · Issue #9012 · dotnet/dotnet-api-docs