Skip to content

Race condition in the example #12721

@RaizaMireHat

Description

@RaizaMireHat

Type of issue

Race Condition

Description

in this part of the code:

                    Interlocked.Add(ref padding, 100);

                    Console.WriteLine("Task {0} enters the semaphore.", Task.CurrentId);

                    // The task just sleeps for 1+ seconds.
                    Thread.Sleep(1000 + padding);

The return value of Interlocked.Add should have been used in Thread.Sleep(1000 + padding) instead of direct usage of padding.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim?view=net-10.0

Content source URL

https://github.com/dotnet/dotnet-api-docs-temp/blob/live/xml/System.Threading/SemaphoreSlim.xml

Document Version Independent Id

00dfa695-b15e-171a-bb3f-6406d5251394

Platform Id

3555abfc-a4c2-7751-ffba-f0547432065b

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Threadingneeds-area-labelAn area label is needed to ensure this gets routed to the appropriate area ownersuntriagedNew issue has not been triaged by the area owner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions