Repository: sharkdp/fd (language: rust)

Issue:
Is `-x` stdout unified across threads?
**What version of `fd` are you using?**
`fd 8.4.0`

I am curious because I would like to calculate the `md5sum` of a bunch of files relative to a single directory. Do I need to worry about the different threads or can I naively just pipe the output of `fd` to a file like I would do with the single-threaded `find`?

e.g. What I would do with `find` is
```
find . -type f -exec md5sum {} ';' &> my-sums.md5
```

I _don't_ want to use `-X` because I am calculating the sum for a lot of multi-GB files so utilizing multiple threads could [^1] be helpful.

If `fd` already unifies the terminal output of its threads, then I would humbly request an addition to the documentation that reflect that much (e.g. another example in the "Command Execution" section?).

[^1] : Disk I/O seems to be the main limiting factor but maybe not.


Discussion / hints:
Nevermind, I think I found where it obviously points out that the std out is unified from the walking threads

https://github.com/sharkdp/fd/blob/a0062b9a1be36a4b1072b8e476462f71c3a1f78a/src/walk.rs#L151-L154

Still leaving this issue up to update the docs...
> Do I need to worry about the different threads or can I naively just pipe the output of `fd` to a file like I would do with the single-threaded `find`?

I assume you mean the following: is there any chance that the different worker threads of `fd` would write interleaved/garbled output because the access to stdout is not synchronized?

If so, then the answer is: no, there is no chance that this would happen - and if it did, I would consider that a severe bug. This is probably why we haven't mentioned it in the docs. It doesn't mean that it's not worth mentioning though :+1: 

> I would like to calculate the `md5sum` of a bunch of files relative to a single directory.

Seems like a good use case for `fd -x`, yes!

> Disk I/O seems to be the main limiting factor but maybe not.

Even if it is, you might still benefit from parallelization! Small benchmark in a folder with 40 files (each around 3 MiB):

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `md5sum *` | 237.5 ± 1.2 | 235.7 | 239.2 | 4.87 ± 0.10 |
| `fd -x md5sum` | 48.8 ± 1.0 | 47.3 | 52.4 | 1.00 |
| `find . -exec md5sum {} \;` | 278.8 ± 1.1 | 277.0 | 280.7 | 5.71 ± 0.12 |


> I _don't_ want to use `-X` because

For very small files, using `-X` might actually be faster because you only need to spawn the `md5sum` process once.


Fix patch:
diff --git a/README.md b/README.md
index 2c89497d8..7af5da606 100644
--- a/README.md
+++ b/README.md
@@ -206,6 +206,13 @@ fd -e jpg -x convert {} {.}.png
 Here, `{}` is a placeholder for the search result. `{.}` is the same, without the file extension.
 See below for more details on the placeholder syntax.
 
+The terminal output of commands run from parallel threads using `-x` will not be interlaced or garbled,
+so `fd -x` can be used to rudimentarily parallelize a task run over many files. 
+An example of this is calculating the checksum of each individual file within a directory.
+```
+fd -tf -x md5sum > file_checksums.txt
+```
+
 #### Placeholder syntax
 
 The `-x` and `-X` options take a *command template* as a series of arguments (instead of a single string).


Test patch: