{-# OPTIONS_GHC -cpp -fglasgow-exts #-} import System.IO import Control.Concurrent.Locking main = do lh <- openBinaryFile "test" ReadMode >>= addLocking str <- readStringAt lh 0 print str readStringAt lh pos = lock lh $ \h -> do saved_pos <- hTell h hSeek h AbsoluteSeek pos str <- hGetLine h hSeek h AbsoluteSeek saved_pos return str