Unsersatnding using SamphoreSlim

Dani_S 3,336 Reputation points
2024-03-24T14:38:16.9633333+00:00

Hi,

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

Thanks,

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

Accepted answer
  1. hossein jalilian 5,560 Reputation points
    2024-03-25T00:33:31.6733333+00:00

    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