多线程环境下可重入函数有什么用?

请您参考如下方法:

线程应仅使用线程安全的可重入函数,以确保数据完整性和不可预测的行为。

All system calls and library functions which end with _r are re-entrant or Mt-Safe functions for e.g ctime_r

参见localtime()的手册页

       ┌───────────────┬───────────────┬─────────────────────────────────┐ 
       │Interface      │ Attribute     │ Value                           │ 
       ├───────────────┼───────────────┼─────────────────────────────────┤ 
       │asctime()      │ Thread safety │ MT-Unsafe race:asctime locale   │ 
       ├───────────────┼───────────────┼─────────────────────────────────┤ 
       │asctime_r()    │ Thread safety │ MT-Safe locale                  │ 
       ├───────────────┼───────────────┼─────────────────────────────────┤ 
       │ctime()        │ Thread safety │ MT-Unsafe race:tmbuf            │ 
       │               │               │ race:asctime env locale         │ 
       ├───────────────┼───────────────┼─────────────────────────────────┤ 
       │ctime_r(),     │ Thread safety │ MT-Safe env locale              │ 
       │gmtime_r(),    │               │                                 │ 
       │localtime_r(), │               │                                 │ 
       │mktime()       │               │                                 │ 
       ├───────────────┼───────────────┼─────────────────────────────────┤ 
       │gmtime(),      │ Thread safety │ MT-Unsafe race:tmbuf env locale │ 
       │localtime()    │               │                                 │ 
       └───────────────┴───────────────┴─────────────────────────────────┘ 


评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!