dotnet / dotnet/docs

Clarify information about the role of threads and async in SemaphoreSlim

Open
#36,104 0 comments 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

Along with the class documentation of SemaphoreSlim the information about the role of threads is confusing me. Since SemaphoreSlim supports async methods, the documentation should highlight if the concept still only applies to Threads or beyond. Does SemaphoreSlim only limit actual threads? Or does it allow for exclusive access by async code that runs on one thread? My understanding is that if I run multiple tasks that await some I/O then I can still synchronize the I/O usage by a SemaphoreSlim.

Also, even when it's about threads using the SemaphoreSlim: The sentence "When a thread requests entry and the count is zero, the thread blocks" to me seems partially incorrect. Isn't the idea of "WaitAsync" that the thread is not "BLOCKED"? Most of the information about async/await tries to explicitly point out that "await" waits in a non-blocking manner. Information like the one in this article can cause confusion.

---
#### Document Details

⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*

* ID: 51e078fd-3a63-8b58-49f8-67e49df9bc9f
* Version Independent ID: f082f7b2-e1a3-aa31-1081-5ca11c954d80
* Content: [Semaphore and SemaphoreSlim](https://learn.microsoft.com/en-us/dotnet/standard/threading/semaphore-and-semaphoreslim)
* Content Source: [docs/standard/threading/semaphore-and-semaphoreslim.md](https://github.com/dotnet/docs/blob/main/docs/standard/threading/semaphore-and-semaphoreslim.md)
* Product: **dotnet-fundamentals**
* GitHub Login: @BillWagner
* Microsoft Alias: **wiwagn**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.