
20 Oct
2010
20 Oct
'10
4:30 p.m.
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