[Haskell-cafe] Re: libefence useful for debugging ghc+ffi programs?

Edward Z. Yang ezyang at MIT.EDU
Wed Oct 20 16:30:43 EDT 2010


Hmm, in that case, one possibility is someone else did an FFI import of
gethostbyname and isn't using the same lock.  Can you check for that?

Edward

Excerpts from Johannes Waldmann's message of Wed Oct 20 16:17:06 -0400 2010:
> 
> > > and indeed, gethostbyname is famous for being non re-entrant.
> 
> it already has a lock in Network.BSD, so I assume it's fine:
> 
> 
> {-# NOINLINE lock #-}
> lock :: MVar ()
> lock = unsafePerformIO $ newMVar ()
> 
> withLock :: IO a -> IO a
> withLock act = withMVar lock (\_ -> act)
> 
> getHostByName :: HostName -> IO HostEntry
> getHostByName name = withLock $ do
>   withCString name $ \ name_cstr -> do
>    ent <- throwNoSuchThingIfNull "getHostByName" "no such host entry"
>                 $ trySysCall $ c_gethostbyname name_cstr
>    peek ent
> 


More information about the Haskell-Cafe mailing list