[Haskell-cafe] Re: threads + IORefs = Segmentation fault?

Achim Schneider barsoap at web.de
Sat Jan 19 08:01:19 EST 2008

David Roundy <droundy at darcs.net> wrote:

> {-# NOINLINE _progressData #-}
> _progressData :: IORef (Map String ProgressData)
> _progressData = unsafePerformIO $ newIORef empty
> updateProgressData :: String 
>	-> (ProgressData -> ProgressData) 
>	-> IO ()
> updateProgressData k f = when (progressMode) $ modifyIORef
> 					_progressData (adjust f k)
The question I'm asking myself is why you would want to modify a
reference to an always empty Map, which would be the case if
unsafePerformIO performs its action every time. If it doesnt' (and
experience suggest that it doesn't, as does the faithful usage of
{-# NOINLINE #-}, BUT YOU'LL NEVER, EVER, KNOW), I'm wondering why you
don't create the IORef in beginTedious and pass it around. Possibly
even with an implicit parameter.

And, yes, without multiple writing threads locking is unnecessary, and
mostly even with multiple writing threads, if they don't read, too.

/me mandates the renaming of unsafePerformIO to

OTOH, I have no idea what causes the segfault. 

(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

More information about the Haskell-Cafe mailing list