[Haskell-cafe] Re: Parallel combinator, performance advice
ndmitchell at gmail.com
Wed Apr 8 09:19:19 EDT 2009
>> I've just found that QSem _ISN'T_ valid below 0, so the above code
>> won't actually work with QSem as it stands.
> I may be missing something, but I guess this code will work if 'newQSem
> (-n)' is replaced with 'newQSemN n', every 'signalQSem sem' with
> 'signalQSemN sem 1' and 'waitQSem sem' with 'waitQSemN sem n'.
Yep, that seems valid. However, the new solution requires an MVar to
store the number of things we're waiting for anyway, so we might as
well use that to also wake up the main thread. Semaphores aren't more
efficient than MVar's, they are in fact implemented in terms of
MVar's, so there is no benefit.
More information about the Haskell-Cafe