Open enobayram opened 5 years ago
I have a similar question related to how silently
works with async
threads. Is it possible to "silence" specific async
s without affecting the others?
As far as I understand this library is not thread-safe, at least on linux. I.e. when one thread wraps an operation with silence
, while that operation is running, it will silence all output to stdout
, even from other threads. And yes, I think it'd be impossible to implement this in a thread-safe way, @enobayram. At least with how putStrLn
and other functions are currently implemented. This is caused by the file-descriptors being shared between OS threads. (See e.g. here.)
@saurabhnanda: Because of this it's not possible to silence one async
thread without affecting others.
Re: documentation: Sorry, don't have many opinions on this. Just wanted to at least answer the question about thread-safety.
What @soenkehahn says is correct.
This library uses hDuplicateTo
which uses the POSIX dup2()
function to redirect file descriptors (FDs), and FDs are per process (thus shared by all OS threads in the process, and thus shared by all Haskell threads).
I'm sure the project would gladly accept a PR to make this as clear as possible.
As far as I know, it's impossible to implement
silently
in a thread-safe manner, but I'd love to be told otherwise. So I'm assuming that the functions in this library aren't thread-safe. In that case, I think the documentation should state that since it may not be obvious to everyone.