I am reading a book called Linux System Programming. Quoting from this book:
What about system calls and other library functions? What if your process is in the middle of writing to a file or allocating memory, and a signal handler writes to the same file or also invokes malloc()? Some functions are clearly not reentrant. If a program is in the middle of executing a nonreentrant function and a signal occurs and the signal handler then invokes that same nonreentrant function, chaos can ensue.
But then it will follow:
Guaranteed-Reentrant Functions
Functions guaranteed to be safely reentrant for use in signals
some functions here..
write()
some functions here..
I am confused, is write()
reentrant, or not? Because I think it clashes with the statement:
What if your process is in the middle of writing to a file?
write
is thread-safe in current Linux kernel. See my answer for details. – Taka