A key, and unfortunately often not a clearly apparent, issue when developing multithreaded applications is that of thread safety. A thread-safe, or, as the man pages like to specify it, MT-Safe, function or API is one that can be safely executed in parallel by multiple threads with no adverse issue.
To understand what this thread-safety issue actually is, let's go back to one of the programs we saw in Appendix A, File I/O Essentials; you can find the source code within the book's GitHub repository: https://github.com/PacktPublishing/Hands-on-System-Programming-with-Linux/blob/master/A_fileio/iobuf.c. In this program, we used fopen(3) to open a file in append mode and then performed some I/O (reads/writes) upon it; we duplicate a small paragraph of that chapter here:
- We fopen(3) a stream (in append mode: a) to our destination, just a regular file in the...