Skip to content

Add a synchronized behavior #271

Description

@kzu

Summary

Ship a non-reentrant lock around a single call. Bulkhead and rate limiting belong to the Polly behavior. This one only excludes overlapping calls on the stunt.

API

The behavior takes an optional lock object. The default is a private object owned by the behavior, so one behavior locks one stunt.

Behavior

  • Acquire the lock before next and release it when the attempt finishes. For Task and ValueTask, that is when Proceed finishes awaiting.
  • The lock is non-reentrant. A second call on the same thread while it is held throws, so a virtual call from a constructor, or from the target, cannot deadlock on this behavior.
  • Document that constructor logic and the target must not call back into a member locked by this behavior.

Acceptance

  • Two overlapping calls run one at a time.
  • The lock is released when a returned task completes, and a later call enters.
  • A re-entrant call on the same thread throws instead of hanging.

Back this issue
Back this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions