[Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

Branimir Maksimovic bmaxa at hotmail.com
Sun Dec 11 17:02:41 EST 2005




>From: Joel Reymont <joelr1 at gmail.com>
>To: "Branimir Maksimovic" <bmaxa at hotmail.com>
>CC: haskell-cafe at haskell.org
>Subject: Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX
>Date: Sun, 11 Dec 2005 19:09:20 +0000
>
>What I do works so I don't see any reason to do it otherwise.

Oh, I 've seen to many programs with undefined behavior floating around
that appears to work.:0)
Problem with mt programs is that they just appear to work but in havy load
situation those errors show once a while.
You have only two choices. Either to clean up code or to live with it.
You didn;t properly initialize SSL as per documention and
you have problem with signal handlers. Both things will work 99% of
the time with spurious crashes on occasion.

>Now, it might work by luck and chance, by some ghc magic or otherwise,
>but it does work and causes me no problems. Not when I press ^C
>and everything shuts down cleanly.
>
>My issues are
>
>1) A phantom sigINT that gets sent to me out of nowhere and

This should be enough reason to scan  for keyboard events instead.
There is no guarantee that SIGINT would be sent only by keyboard.

>2) A deadlock somewhere in my program that I'm trying to troubleshoot
>
>The code:
>
>type Child a = (MVar (), TMVar (ClockTime, (Event a)), MVar ThreadId)
>
>{-# NOINLINE children #-}
>children :: MVar [Child a]
>children = unsafePerformIO $ newMVar []

Just to comment about memory allocation and signals.
Suppose your malloc locks internally.
Let's say thread in the background performs malloc, malloc grabs
the lock. Signal is raised , your handler is called , which calls
malloc and boom deadlock.
If malloc does implement lock free algorithm internaly you don't
have a problem, but that's unlikely.


>
>broadcast :: Show a => Event a -> IO ()
>broadcast event =
>     withMVar children $ \cs -> mapM_ (post event) cs
>         where post event (_, mbx, tmv) =
>                   do tid <- readMVar tmv
>                      trace_ $ "broadcast: Sending " ++ show event
>                                 ++ " to " ++ show tid
>                      time <- getClockTime
>                      atomically $ putTMVar mbx (time, event)

this is lock? same situation as with malloc.
thread locks, then signal arrives , then handler, then deadlock.

Greetings, Bane.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Haskell-Cafe mailing list