Skip to content
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

Is this library thread-safe? If not shouldn't the documentation state that? #6

Open
enobayram opened this issue Feb 1, 2019 · 6 comments · Fixed by #28
Open

Is this library thread-safe? If not shouldn't the documentation state that? #6

enobayram opened this issue Feb 1, 2019 · 6 comments · Fixed by #28

Comments

@enobayram
Copy link

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.

@saurabhnanda
Copy link

I have a similar question related to how silently works with async threads. Is it possible to "silence" specific asyncs without affecting the others?

@soenkehahn
Copy link

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.

@nh2
Copy link
Member

nh2 commented Jul 22, 2020

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.

@andreasabel
Copy link
Collaborator

@andreasabel
Copy link
Collaborator

I clarified the situation in v1.2.5.4:

@sol
Copy link
Member

sol commented Nov 23, 2024

@andreasabel just in case you're not aware of it, Hspec does not suffer from the same limitations as tasty. With Hspec you can capture stdout in a test cases as long as you don't mark that specific test case safe for parallel execution. Other test cases can still be executed in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants