Giter Site home page Giter Site logo

concurrent-extra's People

Contributors

23skidoo avatar basvandijk avatar donatello avatar ip1981 avatar roelvandijk avatar waldheinz avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

concurrent-extra's Issues

ReadWriteLock fairness

The fairness of the ReadWriteLock should be documented. From my observations it seems it is not fair (my writers pile up until there are no readers left). And, if at all possible, it would be really nice if there was a "fair" version of the ReadWriteLock.

haddock fails due to Control.Exception.block missing in base-4.7

There is a conditional import statement that is only in effect when using haddock:

https://github.com/basvandijk/concurrent-extra/blob/master/Control/Concurrent/Event.hs#L72

(I guess this is needed for these links to work: https://github.com/basvandijk/concurrent-extra/blob/master/Control/Concurrent/Event.hs#L171)

Control.Exception.block does not exist since base-4.7.0.0. Therefore haddock fails with

dist/build/tmp-29267/Control/Concurrent/Event.hs:72:34:
    Module ‘Control.Exception’ does not export ‘block’

Test suite failure: GHC 7.4.2, Ubuntu 12.04 64-bit

When building on our Jenkins server, I got the following test failure:

Unpacking to concurrent-extra-0.7.0.6/
Resolving dependencies...
[1 of 1] Compiling Main             ( Setup.hs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
Configuring concurrent-extra-0.7.0.6...
Building concurrent-extra-0.7.0.6...
Preprocessing test suite 'test-concurrent-extra' for
concurrent-extra-0.7.0.6...
[ 1 of 17] Compiling TestUtils        ( TestUtils.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/TestUtils.o )
[ 2 of 17] Compiling Utils            ( Utils.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Utils.o )
[ 3 of 17] Compiling Control.Concurrent.Broadcast ( Control/Concurrent/Broadcast.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Broadcast.o )
[ 4 of 17] Compiling Control.Concurrent.Broadcast.Test ( Control/Concurrent/Broadcast/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Broadcast/Test.o )
[ 5 of 17] Compiling Control.Concurrent.STM.Lock ( Control/Concurrent/STM/Lock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/STM/Lock.o )
[ 6 of 17] Compiling Control.Concurrent.STM.Lock.Test ( Control/Concurrent/STM/Lock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/STM/Lock/Test.o )
[ 7 of 17] Compiling Control.Concurrent.Lock ( Control/Concurrent/Lock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Lock.o )
[ 8 of 17] Compiling Control.Concurrent.Lock.Test ( Control/Concurrent/Lock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Lock/Test.o )
[ 9 of 17] Compiling Control.Concurrent.RLock ( Control/Concurrent/RLock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/RLock.o )
[10 of 17] Compiling Control.Concurrent.ReadWriteLock ( Control/Concurrent/ReadWriteLock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteLock.o )
[11 of 17] Compiling Control.Concurrent.ReadWriteLock.Test ( Control/Concurrent/ReadWriteLock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteLock/Test.o )
[12 of 17] Compiling Control.Concurrent.ReadWriteVar ( Control/Concurrent/ReadWriteVar.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteVar.o )
[13 of 17] Compiling Control.Concurrent.ReadWriteVar.Test ( Control/Concurrent/ReadWriteVar/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteVar/Test.o )
[14 of 17] Compiling Control.Concurrent.Event ( Control/Concurrent/Event.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Event.o )
[15 of 17] Compiling Control.Concurrent.Event.Test ( Control/Concurrent/Event/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Event/Test.o )
[16 of 17] Compiling Control.Concurrent.RLock.Test ( Control/Concurrent/RLock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/RLock/Test.o )
[17 of 17] Compiling Main             ( test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Main.o )
Linking dist/build/test-concurrent-extra/test-concurrent-extra ...
Preprocessing library concurrent-extra-0.7.0.6...
[1 of 8] Compiling Utils            ( Utils.hs, dist/build/Utils.o )
[2 of 8] Compiling Control.Concurrent.STM.Lock ( Control/Concurrent/STM/Lock.hs, dist/build/Control/Concurrent/STM/Lock.o )
[3 of 8] Compiling Control.Concurrent.Broadcast ( Control/Concurrent/Broadcast.hs, dist/build/Control/Concurrent/Broadcast.o )
[4 of 8] Compiling Control.Concurrent.Event ( Control/Concurrent/Event.hs, dist/build/Control/Concurrent/Event.o )
[5 of 8] Compiling Control.Concurrent.Lock ( Control/Concurrent/Lock.hs, dist/build/Control/Concurrent/Lock.o )
[6 of 8] Compiling Control.Concurrent.RLock ( Control/Concurrent/RLock.hs, dist/build/Control/Concurrent/RLock.o )
[7 of 8] Compiling Control.Concurrent.ReadWriteLock ( Control/Concurrent/ReadWriteLock.hs, dist/build/Control/Concurrent/ReadWriteLock.o )
[8 of 8] Compiling Control.Concurrent.ReadWriteVar ( Control/Concurrent/ReadWriteVar.hs, dist/build/Control/Concurrent/ReadWriteVar.o )
In-place registering concurrent-extra-0.7.0.6...
Running 1 test suites...
Test suite test-concurrent-extra: RUNNING...
Pessimistic locking:
  Event:
    set wait a: [OK]
    set wait b: [OK]
    set wait c: [OK]
    set wait d: [OK]
    conc set wait: [OK]
    multi wake: [Failed]

    exception: [OK]
    wait timeout: [OK]
    wait blocks: [OK]
  Lock:
    acquire release: [OK]
    acquire acquire: [OK]
    new release: [OK]
    new unlocked: [OK]
    newAcquired locked: [OK]
    acq rel unlocked: [OK]
    conc release: [OK]
    wait: [OK]
  STM.Lock:
    acquire release: [OK]
    acquire acquire: [OK]
    new release: [OK]
    new unlocked: [OK]
    newAcquired locked: [OK]
    acq rel unlocked: [OK]
    conc release: [OK]
    wait: [OK]
  RLock:
    recursive acquire: [OK]
    conc acquire: [Failed]

  ReadWriteLock:
    test1: [OK]
    test2: [OK]

         Test Cases   Total       
 Passed  27           27          
 Failed  2            2           
 Total   29           29          
Test suite test-concurrent-extra: FAIL
Test suite logged to:
dist/test/concurrent-extra-0.7.0.6-test-concurrent-extra.log
0 of 1 test suites (0 of 1 test cases) passed.

Test suite failure: GHC 7.6.3, Ubuntu 12.04 64-bit

Discovered during Stackage build:

Unpacking to concurrent-extra-0.7.0.5/
Resolving dependencies...
[1 of 1] Compiling Main ( Setup.hs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
Configuring concurrent-extra-0.7.0.5...
Building concurrent-extra-0.7.0.5...
Preprocessing test suite 'test-concurrent-extra' for
concurrent-extra-0.7.0.5...
[ 1 of 17] Compiling TestUtils ( TestUtils.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/TestUtils.o )
[ 2 of 17] Compiling Utils ( Utils.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Utils.o )
[ 3 of 17] Compiling Control.Concurrent.Broadcast ( Control/Concurrent/Broadcast.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Broadcast.o )
[ 4 of 17] Compiling Control.Concurrent.Broadcast.Test ( Control/Concurrent/Broadcast/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Broadcast/Test.o )
[ 5 of 17] Compiling Control.Concurrent.STM.Lock ( Control/Concurrent/STM/Lock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/STM/Lock.o )
[ 6 of 17] Compiling Control.Concurrent.STM.Lock.Test ( Control/Concurrent/STM/Lock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/STM/Lock/Test.o )
[ 7 of 17] Compiling Control.Concurrent.Lock ( Control/Concurrent/Lock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Lock.o )
[ 8 of 17] Compiling Control.Concurrent.Lock.Test ( Control/Concurrent/Lock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Lock/Test.o )
[ 9 of 17] Compiling Control.Concurrent.RLock ( Control/Concurrent/RLock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/RLock.o )
[10 of 17] Compiling Control.Concurrent.ReadWriteLock ( Control/Concurrent/ReadWriteLock.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteLock.o )
[11 of 17] Compiling Control.Concurrent.ReadWriteLock.Test ( Control/Concurrent/ReadWriteLock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteLock/Test.o )
[12 of 17] Compiling Control.Concurrent.ReadWriteVar ( Control/Concurrent/ReadWriteVar.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteVar.o )
[13 of 17] Compiling Control.Concurrent.ReadWriteVar.Test ( Control/Concurrent/ReadWriteVar/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/ReadWriteVar/Test.o )
[14 of 17] Compiling Control.Concurrent.Event ( Control/Concurrent/Event.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Event.o )
[15 of 17] Compiling Control.Concurrent.Event.Test ( Control/Concurrent/Event/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/Event/Test.o )
[16 of 17] Compiling Control.Concurrent.RLock.Test ( Control/Concurrent/RLock/Test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Control/Concurrent/RLock/Test.o )
[17 of 17] Compiling Main ( test.hs, dist/build/test-concurrent-extra/test-concurrent-extra-tmp/Main.o )
Linking dist/build/test-concurrent-extra/test-concurrent-extra ...
Preprocessing library concurrent-extra-0.7.0.5...
[1 of 8] Compiling Utils ( Utils.hs, dist/build/Utils.o )
[2 of 8] Compiling Control.Concurrent.STM.Lock ( Control/Concurrent/STM/Lock.hs, dist/build/Control/Concurrent/STM/Lock.o )
[3 of 8] Compiling Control.Concurrent.Broadcast ( Control/Concurrent/Broadcast.hs, dist/build/Control/Concurrent/Broadcast.o )
[4 of 8] Compiling Control.Concurrent.Event ( Control/Concurrent/Event.hs, dist/build/Control/Concurrent/Event.o )
[5 of 8] Compiling Control.Concurrent.Lock ( Control/Concurrent/Lock.hs, dist/build/Control/Concurrent/Lock.o )
[6 of 8] Compiling Control.Concurrent.RLock ( Control/Concurrent/RLock.hs, dist/build/Control/Concurrent/RLock.o )
[7 of 8] Compiling Control.Concurrent.ReadWriteLock ( Control/Concurrent/ReadWriteLock.hs, dist/build/Control/Concurrent/ReadWriteLock.o )
[8 of 8] Compiling Control.Concurrent.ReadWriteVar ( Control/Concurrent/ReadWriteVar.hs, dist/build/Control/Concurrent/ReadWriteVar.o )
In-place registering concurrent-extra-0.7.0.5...
Running 1 test suites...
Test suite test-concurrent-extra: RUNNING...
Pessimistic locking:
Event:
set wait a: [OK]
set wait b: [OK]
set wait c: [OK]
set wait d: [OK]
conc set wait: [OK]
multi wake: [OK]
exception: [OK]
wait timeout: [OK]
wait blocks: [OK]
Lock:
acquire release: [OK]
acquire acquire: [OK]
new release: [OK]
new unlocked: [OK]
newAcquired locked: [OK]
acq rel unlocked: [OK]
conc release: [Failed]

wait: [OK]

STM.Lock:
acquire release: [OK]
acquire acquire: [OK]
new release: [OK]
new unlocked: [OK]
newAcquired locked: [OK]
acq rel unlocked: [OK]
conc release: [OK]
wait: [OK]
RLock:
recursive acquire: [OK]
conc acquire: [OK]
ReadWriteLock:
test1: [OK]
test2: [OK]

     Test Cases   Total       

Passed 28 28
Failed 1 1
Total 29 29
Test suite test-concurrent-extra: FAIL
Test suite logged to:
dist/test/concurrent-extra-0.7.0.5-test-concurrent-extra.log
0 of 1 test suites (0 of 1 test cases) passed.

Simplify `Broadcast`?

I think Broadcast could be (almost) simplified to newtype Broadcast a = Broadcast { unBroadcast :: MVar a }, where "silent" is represented by an empty MVar and "broadcasting" is represented by a full MVar. listen would then just be readMVar . unBroadcast and broadcast would be putMVar x . unBroadcast. However, signal might be more difficult, since it would putMVar and then immediately takeMVar. I'm not sure if the runtime guarantees that the threads blocked on the MVar can read it before signal continues.

Add Support for Cyclic Barrier

This Java concurrency primitive is useful, and not easily replicated using the existing primitives in this package. The API could be similar to RLock, except there is no concept of ownership (in particular, any thread can call release).

I'm happy to submit a PR if you're interested in adding this.

GHC 7.8 support

I've tested locally, and bumping versions bounds on base is all that's necessary to compile successfully.

ReadWriteLock.releaseRead: already released

I've just been hit by the error message

ads: Control.Concurrent.ReadWriteLock.releaseRead: already released

This must be coming from my Store module. Because I'm only ever using the with* functions on the RWLock, I'd guess my usage should be safe and this message should never be seen, right? This happens using GHC 7.6.3 on 64-bit Linux.

Looking through the code my first idea was that the Int on the Read state might overflow, but while the load can be quite intense, I'm pretty sure I don't have that many parallel reads.

`RLock` may starve thread?

Control.Concurrent.RLock.acquire waits on the inner Lock and then tries to acquire the RLock again. However, what if between these two operations, another thread managed to acquire the RLock? The thread has to wait again, potentially forever. The doc comment says that the runtime guarantees that the woken thread completes its acquire operation, but I don't see how that can be achieved in this situation. Did I maybe miss something or is this a bug?

Acquire lock with timeout

Similarly to Broadcast's listenTimeout, it may be useful to have:

  • acquireTimeout :: Lock -> Integer -> IO Bool and
  • withTimeout :: Lock -> Integer -> IO a -> IO (Maybe a)

that try to acquire the lock in the provided time or fail (returning False and Nothing correspondingly).

Is there a technical/logical limitation for this not to work?
Is using timeout with acquire really undesirable?

Documentation: "modify" instead of "with"

Holger Reinhardt reported:
the documentation of RWVar states: "Furthermore with is fully sequential and will also block on concurrent calls of with.". I think this should be "modify" instead of "with".

RLock and asynchronous exceptions

I believe that RLock needs uninterruptible masking around the outer MVar. Otherwise, since takeMVar is interruptible, it may happen that release gets interrupted after taking the outer lock but before the inner lock is released.

concurrent-extra-0.7.0.9 test suite failure

Citing from http://hydra.cryp.to/build/1114863/nixlog/1/raw:

Running 1 test suites...
Test suite test-concurrent-extra: RUNNING...
Pessimistic locking:
  Event:
    set wait a: [OK]
    set wait b: [OK]
    set wait c: [OK]
    set wait d: [OK]
    conc set wait: [OK]
    multi wake: [OK]
    exception: [OK]
    wait timeout: [OK]
    wait blocks: [OK]
  Lock:
    acquire release: [OK]
    acquire acquire: [OK]
    new release: [OK]
    new unlocked: [OK]
    newAcquired locked: [OK]
    acq rel unlocked: [OK]
    conc release: [OK]
    wait: [OK]
  STM.Lock:
    acquire release: [OK]
    acquire acquire: [OK]
    new release: [OK]
    new unlocked: [OK]
    newAcquired locked: [OK]
    acq rel unlocked: [OK]
    conc release: [OK]
    wait: [OK]
  RLock:
    recursive acquire: [OK]
    conc acquire: [OK]
  ReadWriteLock:
    test1: [OK]
    test2: [OK]
    stressTest: [Failed]


         Test Cases   Total       
 Passed  29           29          
 Failed  1            1           
 Total   30           30          
Test suite test-concurrent-extra: FAIL

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.