[Haskell-cafe] Re: libefence useful for debugging ghc+ffi programs?
Johannes Waldmann
waldmann at imn.htwk-leipzig.de
Wed Oct 20 16:17:06 EDT 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