basvandijk / concurrent-extra

Extra concurrency primitives
Other
17 stars 5 forks source link

Fix race in ReadWriteLock.(try)acquireWrite, and add a partial test case #9

Closed waldheinz closed 10 years ago

waldheinz commented 10 years ago

For me, this fixes issue #8. Previously, the Write -> Write state change in acquireWrite was accomplished by the sequence

putMVar state st
Lock.acquire writeLock
void $ swapMVar state Write

As I see it, this is problematic because there is nothing preventing a reader slip in between the putMVar and acquiring the write lock (well, the reader wouldn't even care if the write lock was acquired), so I guess the void threw away a Read state sometimes. There was a similar problem with tryAcquireWrite, which should be fixed as well.

I also added a new test case for this, but it's not in a good state currently: The test is recognized as passed even when the bug strikes. The only way to know is to have a look at the test's log file. I included it anyway because at least it's no worse than before.

basvandijk commented 10 years ago

Thanks for the fix!

I also made sure the stressTest will fail on a broken implementation.

Released as 0.7.0.8.

waldheinz commented 10 years ago

That was released before I managed to work out cabal sandbox add-source, thanks. :-)