I was browsing through the source for Semaphore.lhs when I noticed a bug
in the implementation for waitQSemN. If I understand the workings and
semantics correctly, the value of 'avail' specifies how many resources
are available and the value of 'sz' specifies the number of resources
requested by the caller. The bug is that the code only checks to see "if
avail > 0" instead of checking "if avail >= sz" when it decides whether
or not to grant access to the resource. Also, when it updates the value
of 'avail', it sets it to "avail-1" instead of "avail-sz". Looks like
the source of this bug is due to a copy-and-paste from waitQSem. (Also,
in the 'else' clause of the function, it shouldn't blindly write a 0
into the new value of 'avail', it keep the value of 'avail' as it is.)

- Michael Hobbs


FYI, The reason I was reading through the source was because I wanted to
know what it was that these semaphore functions did and how they worked,
but couldn't find documentation for them anywhere. I later learned that
my copy of "The Concurrent Haskell Paper" had had that section edited
away for brevity. :-/

Reply via email to