Opened 16 years ago

Closed 15 years ago

Last modified 50 years ago

#228 closed bug (Fixed)

DiffArray deadlock

Reported by: simonmar Owned by: simonmar
Priority: low Milestone:
Component: libraries/base Version: 6.2.1
Keywords: Cc:
Operating System: Architecture:
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Posted to, by Lauri Alanko

The following program gets stuck in ghci, and when
compiled with ghc and
run, fails with "Fail: thread blocked indefinitely".

import Data.Array.Diff
main = print (a // [((a ! 0, 1))] ! 0)
    where a = array (0,0) [(0,0)] :: DiffArray Int Int

When DiffArray is replaced with Array, it just prints
out "1" as it

Apparently there is some kind of a deadlock internally,
with the update
operation holding the lock already before the lookup
operation is

I think the solution is to evaluate all the indices in
the argument to
replaceDiffArray _before_ obtaining the lock. Changing
a single line in
Diff.hs gives a partial quick fix:

@@ -287 +287 @@
-a `replaceDiffArray` ies = do
+a `replaceDiffArray` ies = sum (map fst ies) `seq` do

However, in DiffUArray, when the underlying imperative
array is unboxed,
the operation is strict also in the elements, and then
(and _only_ then)
the elements, too, need to be evaluated before the MVar
is taken, or
otherwise their evaluation may lead to a deadlock.

I'm not really sure what would be the neatest solution.

Lauri Alanko

Change History (1)

comment:1 Changed 15 years ago by simonmar

Status: assignedclosed
Logged In: YES 

Fixed, thanks.
Note: See TracTickets for help on using tickets.