Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've developed a theory. I believe that the large allocation is triggering a garbage collection, but the collection itself cannot commence until all threads are ready. All threads but the one reading the file block until the read has completed, but unfortunately the entire read happens in one call, so it takes a while. Then the GC is performed, and everything is fine after.</p> <p>I also have a workaround, but I don't think it guarantees that the program won't block (although I have not gotten it to block yet, others have reported that it still blocks on their machines). Run the following with <code>+RTS -N -qg</code> (if you allow parallel GC it sometimes blocks, but not always):</p> <pre><code>module Main where import Data.IORef import qualified Data.ByteString as S import Control.Monad import Control.Concurrent main :: IO () main = do done &lt;- newEmptyMVar forkIO $ do var &lt;- newIORef False forkIO $ forever $ do status &lt;- readIORef var if status then putStrLn "main: file was read" else putStrLn "main: file not yet read" threadDelay 10000 threadDelay 200000 putStrLn "&gt;&gt;! going to read file" --threadDelay 200000 -- _str &lt;- S.readFile "large" putStrLn "&gt;&gt;! finished reading file" writeIORef var True threadDelay 200000 putMVar done () takeMVar done </code></pre> <p>I have no theories yet about <em>why</em> the GC is waiting for the syscall. I can't seem to replicate the issue with my own safe and unsafe bindings to <code>sleep</code> and adding <code>performGC</code> to the status loop.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload