重入和线程安全函数有所不同,我不知道以_r结尾的Linux函数是否是线程安全的,可重入的(我的意思是异步信号安全)或两者兼而有之,
They are thread-safe.
Stevens/Rago APUE teaches the distinction between thread-safe functions (reentrant with respect to being called by multiple threads), and async-signal-safe functions (reentrant with respect to signal handlers, so can be called safely from within a signal handler).
APUE ch 12.5 Reentrancy lists ~79 functions which are not thread-safe, then ~11 have equivalents which are reentrant, those are the *_r functions. That means those 11 can be called by multiple threads at the same time.
APUE ch 10.6 Reentrant Functions lists ~135 functions which are async-signal-safe. They block signal delivery when needed. So, you can use them in signal handler code. Note, async-signal-safeness only matters when functions are called inside a signal handler. That may motivate one to not write signal handler code, as further details are tricky.
Kerrisk TLPI ch 21 Signals: Signal Handlers has its own table of functions which are async-signal-safe. Interestingly it is not quite same as APUE.
None of the *._r are listed as async-signal-safe by either of these references.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.