Skip to content

ReentrantSemaphore - Implement EnterAsync with timeout #1362

@robert-at-pieces

Description

@robert-at-pieces

Is your feature request related to a problem? Please describe.

SemaphoreSlim and AsyncSemaphore have been banned via analyzers with the replacement preference being ReentrantSemaphore due to it being JTF aware.

AsyncSemaphore's EnterAsync implementation allows for a timeout parameter

ReentrantSemaphore's ExecuteAsync implementation always enters the underlying AsyncSemphare with an infinite timeout

Describe the solution you'd like

AsyncSemaphore supports an EnterAsync timeout. I would like to see ReentrantSemaphore allow for this parameter to be passed as an argument during ExecuteAsync.

Describe alternatives you've considered

Unless I am mistaken,
You can partially work around this by passing a cancellation token that times out, but this timeout is not specific to acquiring the lock. If the critical section is a long running operation, it is possible that a passed in cancellation token would cancel even though entrance into the critical section was achieved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions