hoylen / dart-mutex Goto Github PK
View Code? Open in Web Editor NEWMutual exclusion for Dart
License: BSD 3-Clause "New" or "Revised" License
Mutual exclusion for Dart
License: BSD 3-Clause "New" or "Revised" License
mutex_readwrite_test.dart seems to be flaky.
From time to time I get this while running the tests for dart-mutex
Expected: a value less than <2100>...
Expected: a value less than <2100>
Actual: <2205>
Which: is not a value less than <2100>
Since DateTime.now()
is used it might cause issues because of clock times.
from here:
https://github.com/hoylen/dart-mutex/blob/master/test/mutex_readwrite_test.dart#L171
expect(ms, greaterThan(delay * 10));
expect(ms, lessThan(delay * 10 + overhead));
expect(account.numWrites, equals(10));
Can this use a fake clock instead?
Is it possible to share a Mutex
through different isolates?
We've been debugging an issue and have discovered that the mutex isn't working. The mutex is able to .acquire()
even though isLocked == true
.
static Mutex mutex = new Mutex();
static testMutex() async {
mutex.acquire();
print("Acquired mutex");
try {
await Future.delayed(Duration(seconds: 1));
} finally {
mutex.release();
print("Released mutex");
}
}
Running the testMutex() method results in:
Acquired Mutex
Acquired Mutex
Acquired Mutex
Acquired Mutex
Released mutex
Released mutex
Released mutex
Released mutex
The Mutex isn't causing subsequent acquire() calls to block as expected. We're testing on iOS 13.7 using an iPhone 8 simulator.
This test below will timed out.
import 'package:mutex/mutex.dart';
import 'package:test/test.dart';
import 'dart:async';
void main() {
group('Exclusive lock tests', () {
test('test5', () async {
var mutex = ReadWriteMutex();
unawaited(sharedLoop1(mutex));
await mySleep(10);
unawaited(sharedLoop1(mutex));
await mySleep(10);
unawaited(sharedLoop1(mutex));
await mySleep(10);
unawaited(sharedLoop1(mutex));
await mySleep(10);
unawaited(sharedLoop1(mutex));
await mySleep(1000);
await mutex.acquireWrite();
mutex.release();
expect('a', 'a');
});
});
}
Future<void> sharedLoop1(ReadWriteMutex mutex) async {
while (true) {
await mutex.protectRead(() async {
await mySleep(50);
});
}
}
Future<void> mySleep([int ms = 1000]) async {
await Future<void>.delayed(Duration(milliseconds: ms));
}
The documentation should be changed to answer this question.?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.