Skip to content

ThreadSafeBus: read state and protocol without the bus locks - #2152

Open
DanShinde wants to merge 1 commit into
hardbyte:mainfrom
DanShinde:thread-safe-bus-state-no-lock
Open

DanShinde wants to merge 1 commit into
hardbyte:mainfrom
DanShinde:thread-safe-bus-state-no-lock

Conversation

@DanShinde

Copy link
Copy Markdown
Contributor

Summary of Changes

  • ThreadSafeBus.state and ThreadSafeBus.protocol took both the send and the receive lock. A thread blocked in recv() holds the receive lock for its whole timeout, so reading the state from another thread (e.g. while a Notifier is running) waited for that recv() to return.
  • Both getters now read from the wrapped bus without the locks. The state setter keeps them.
  • New back-to-back test: one thread blocks in recv(1.0), the main thread reads state and protocol and must get them in well under the timeout. It fails on main (waits ~1 s) and passes with the change.

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

The state and protocol getters took both the send and the receive lock.
A thread blocked in recv() holds the receive lock for its whole timeout,
so reading the state from another thread waited until that recv()
returned.

Read both without the locks; they only read from the wrapped bus.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

thread_safe_bus.state (getter) should not use locks

1 participant