Created
February 20, 2013 03:45
-
-
Save wavewave/4992706 to your computer and use it in GitHub Desktop.
testing file locking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Concurrent | |
| import System.IO | |
| import System.Posix.Files | |
| import System.Posix.IO | |
| import System.Posix.Types | |
| main = do | |
| putStrLn "file lock test" | |
| let fp = "test.txt" | |
| fd <- openFd fp ReadWrite mode defaultFileFlags | |
| r <- getLock fd (ReadLock,AbsoluteSeek,0,0) | |
| case r of | |
| Nothing -> do | |
| putStrLn "Nothing" | |
| setLock fd (WriteLock,AbsoluteSeek,0,0) | |
| Just _ -> putStrLn "Just _" | |
| threadDelay 50000000 | |
| closeFd fd | |
| where mode = Just (unionFileModes ownerReadMode ownerWriteMode) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment