2

This answer recommends fts as a good way to have a reentrant filesystem traversal. While reading the manpages, however, I noticed that fts_read and fts_children are marked as MT-Unsafe.

I could not find anywhere information on why it was marked as such. I found this thread, so I suspect the reason is because of chdir being called (two threads will try to chdir the process at the same time, it can't be good).

If that is so, I guess that passing FTS_NOCHDIR would be enough to have thread safety. Is there any other reason I don't see?

(And for the record, I'm very surprised that we came to this day without having a good reentrant, reasonable to use way of scanning through a filesystem tree! Seriously? ☺)

Dacav
  • 13,590
  • 11
  • 60
  • 87
  • Regarding how we came to this day without havign a reentrant way to scan the filesystem: it is by definition an IO-bound task, so there's likely not going to be much gain from doing it in parallel. All your threads will just end up waiting for the same physical medium anyway so why bother? – Britton Kerin Nov 24 '18 at 22:22
  • @BrittonKerin - In a single-threaded program there are also signals and other sources of interruption. Also reentrant code fosters better quality in general, even outside the scope of multi-threaded programming. Quality matters :) – Dacav Nov 26 '18 at 07:11

0 Answers0