haskell-fswatch / hfsnotify

Unified Haskell interface for basic file system notifications
BSD 3-Clause "New" or "Revised" License
136 stars 40 forks source link

Doesn't work on macOS unless -N is specified #89

Open neongreen opened 5 years ago

neongreen commented 5 years ago

When using forever $ threadDelay 1000000, I needed both -threaded and -with-rtsopts=-N to get it to work. When using forever $ getLine, I only needed -threaded. Perhaps this should be mentioned in the docs.

    forkIO $ FSNotify.withManager $ \manager -> do
        directory <- takeDirectory <$> makeAbsolute (settingsRoot settings)
        let predicate = const True
        FSNotify.watchDir manager directory predicate print
        forever $ threadDelay 1000000
thomasjm commented 3 years ago

This is similar in spirit to #50.

The GHC docs say that omitting -N is equivalent to passing -N1. I don't totally understand why your program wouldn't work when run with a single Haskell capability. Does it fail to print anything at all? I'd expect the main thread to yield to the callback thread in between threadDelay 1000000 calls but maybe some deadlock is happening with foreign function calls.

I'm not sure if there are any checks we can add to the code to prevent this, the same way we did to check for -threaded on Windows. Like you said, doing non-blocking stuff in the event handler with -N1 is a valid way to use this library. But a note in the docs about threading pitfalls sounds good.