dotnet / dotnet/dotnet-api-docs
Race condition in the example
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
### 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
Contributor guide
Assessment
This issue has not been assessed yet.