-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hPutStrLn
in multiple threads
#442
Comments
I'd rather document that none of EDIT: And e.g. if people need to output two lines, thread-safe |
@phadej yes, such a note can be useful to avoid confusion |
hPutStrLn :: Handle -> ByteString -> IO ()
hPutStrLn h ps
| length ps < 1024 = hPut h (ps `B.snoc` 0x0a)
| otherwise = hPut h ps >> hPut h (B.singleton 0x0a) -- don't copy This is still not atomic, but much less annoying in practice. I think doing the same trick in |
I initially thought _Why not use hPutBuilder _ hPutBuilder h (fromText ps <> fromText "\n") but then found that the text package doesn't have an equivalent - is there a good reason for this? |
@Bodigrim but length can be expensive O(n) |
We don't need |
@axman6-da |
This seems to be a duplicate of #242. It would be nice if someone has energy if not fix it completely then at least alleviate in typical scenarios. |
Function to print text with newline performs it as two separate actions - first is to print message and second - to
print newline symbol.
This way there is issues with computations in multiple threads, so newline symbol sometimes printed in wrong place.
Possible solution here is to redefine
hPutStrLn
like this:Not sure what is the reason of current implementation..
I found that issue when used
co-log
and I've provided PR with a fix (co-log/co-log#243), but the source problem istext
library.The text was updated successfully, but these errors were encountered: