Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Added an optional timeout to the Mailbox.take method #27

Closed
wants to merge 28 commits into from

Conversation

bsutton
Copy link

@bsutton bsutton commented Jul 25, 2024

This required changes to the underlying Mutex.runLocked and ConditionalVariable.wait methods.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.

The changes are backwards compatible simply adding an optional 'timeout' argument to each of the noted methods.

The changes provide greater flexibility in how the methods are used and will also aid in debugging dead locks (which is what prompted me to do the work).

@bsutton
Copy link
Author

bsutton commented Jul 31, 2024

I've released a temp package to pub.dev if anyone needs this functionality urgently
https://pub.dev/packages/native_synchronization_temp

Copy link
Contributor

@mraleph mraleph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

CHANGELOG.md Show resolved Hide resolved
lib/mailbox.dart Show resolved Hide resolved
calloc.free(mailbox.ref.buffer);
calloc.free(mailbox);
static final finalizer = Finalizer((mailbox) {
final p = mailbox! as Pointer<_MailboxRepr>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I dev using strong type lint options and the linter was complaining, so I fixed it.

Copy link
Contributor

@mraleph mraleph Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was it complaining about? The change makes the code less typed: finalizer had static type Finalizer<Pointer<_MailboxRepr>> after your change this type is lost and you are resorting to runtime casting for some reason.

Please revert this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not resolved

lib/mailbox.dart Outdated Show resolved Hide resolved
lib/posix.dart Outdated Show resolved Hide resolved
lib/posix.dart Outdated Show resolved Hide resolved
lib/src/bindings/pthread.dart Show resolved Hide resolved
lib/src/bindings/pthread.dart Outdated Show resolved Hide resolved
lib/windows.dart Show resolved Hide resolved
bsutton and others added 8 commits August 9, 2024 09:56
… the calculations for remaining time when the wait wakes up for sperious reasons.

Change the while termination in takeTimed to check for _stateEmpty rather than !_stateFull in anticipation of the mailbox supporting multiple messages rather than jus the single message it currently supports.
@bsutton
Copy link
Author

bsutton commented Aug 9, 2024

changes as requested and merged with main.

@bsutton
Copy link
Author

bsutton commented Aug 9, 2024

I've just had to raise an issue with the dart team as ffi seems to be crashing with the latest merges from main.

dart-lang/sdk#56412

So perhaps best no to merge this pr until we see a response on the noted issue.

unawaited(
spawnLockedMutex(mutex.asSendable, const Duration(seconds: 10)));

/// give the isoalte a chance to start.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Typo: isolate.
  • do not use doc comments inside functions.
  • Please capitalize sentences in comments and end them with a ..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not resolved?

@bsutton
Copy link
Author

bsutton commented Aug 14, 2024

I've removed the check for a closed mailbox from Mailbox.take() with a timeout to side set the FFI crash.

Do we wait for an fix to ffi before we release?

final remainingTime = _remainingTime(timeout, start);
_condVar.wait(_mutex, timeout: remainingTime);
}
// if (_mailbox.ref.state == _stateClosed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code?

@mraleph
Copy link
Contributor

mraleph commented Aug 15, 2024

Tests are not passing and there are still unresolved comments.

Added so a user can determine what a call to Mailbox.put failed (e.g. the box was full or closed).
@devoncarew
Copy link
Contributor

Hi - thanks for the PR. FYI that the source-of-truth for this package has moved to our dart-lang/labs monorepo; https://github.com/dart-lang/labs/tree/main/pkgs/native_synchronization.

I'll close this PR, but feel free to re-create it against the new package location if this PR is still active.

@devoncarew devoncarew closed this Sep 26, 2024
@mraleph
Copy link
Contributor

mraleph commented Sep 27, 2024

The PR was stalled mostly because I was distracted - I will take a landing this code in the monorepo when I get a chance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants