Code Monkey home page Code Monkey logo

dart-mutex's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dart-mutex's Issues

flaky mutex read write test

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?

Simple mutex use case not working

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.

Can not acquire write lock.

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));
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.