Can anything bad happen (like undefined behavior, file corruption, etc.) if several threads concurrently call fflush()
on the same FILE*
variable?
Clarification: I don't mean writing the file concurrently. I only mean flushing it concurrently.
The threads do not read or write the file concurrently (they only write the file inside a critical section, one thread at a time). They only flush outside of the critical section, to release the critical section sooner so to let the others do the other work (except file writing).
Though it may happen that one thread is writing the file (inside the critical section), while another thread(s) is flushing the file (outside the critical section).