|
Re: Implementing computations with timeout: msg#00094lang.haskell.cafe
Tomasz Zielonka <tomasz.zielonka@xxxxxxxxx> writes: > import Control.Concurrent (forkIO, threadDelay) > import Control.Concurrent.STM > > withTimeout :: Int -> STM a -> IO (Maybe a) > withTimeout time fun = do > mv <- atomically newEmptyTMVar > tid <- forkIO $ do > threadDelay time > atomically (putTMVar mv ()) > x <- atomically (fmap Just fun `orElse` (takeTMVar mv >> return > Nothing)) > killThread tid > return x Isn't this buggy if fun just keeps working without throwing an exception or using retry? I meant wholly inside STM - if we use IO as the signature then using the TMVar has few advantages over using an MVar. - Einar Karttunen |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Implementing computations with timeout: 00094, Tomasz Zielonka |
|---|---|
| Next by Date: | Re: Implementing computations with timeout: 00094, Tomasz Zielonka |
| Previous by Thread: | Re: Implementing computations with timeouti: 00094, Tomasz Zielonka |
| Next by Thread: | Re: Implementing computations with timeout: 00094, Tomasz Zielonka |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |