Unsersatnding using SamphoreSlim

Dani_S 2,726 Reputation points


How does SamphoreSlim working when multiple thread are reaching to it?


Microsoft Technologies based on the .NET software framework.
3,367 questions
0 comments No comments
{count} votes

Accepted answer
  1. hossein jalilian 2,370 Reputation points

    Thanks for posting your question in the Microsoft Q&A forum.

    SemaphoreSlim manages access to a limited resource by maintaining an internal counter. When threads request access, the counter is decremented if slots are available. Threads are granted immediate access if the counter is positive, otherwise, they wait in a FIFO queue. When a thread releases access, the counter is incremented, allowing the next waiting thread to proceed. SemaphoreSlim is efficient and lightweight, ideal for controlling shared resource access across multiple threads without excessive blocking or context switching.

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful