有没有在多线程应用程序安全地使用错误号的方法吗? [英] Is there a way to use errno safely in a multi-threaded application?

查看:115
本文介绍了有没有在多线程应用程序安全地使用错误号的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你正在写一个使用的系统/库调用,使errno的使用,以指示错误类型,有没有使用errno的一个安全的方式在多线程应用程序?如果不是,有一些其他方式来指示错误的发生,而不是仅仅为发生了错误?

If you are writing a multi-threaded application that uses system/library calls that make use of errno to indicate the error type, is there a safe way to use errno? If not, is there some other way to indicate the type of error that occurred rather than just that an error has occurred?

推荐答案

如果你的标准库是多线程的认识,那么它可能有一个的#define 的更改错误号成一个函数调用返回的线程局部错误返回值。但是,要使用这个你通常的必须的包括< errno.h中> ,而不是依靠一个 EXTERN 声明。

If your standard library is multithread aware, then it probably has a #define that changes errno into a function call that returns a thread-local error return value. However, to use this you generally must include <errno.h>, rather than relying on an extern declaration.

我发现它解决过这个问题的文章线程安全性和POSIX.1

I found an article Thread-safety and POSIX.1 which addresses this very question.

这篇关于有没有在多线程应用程序安全地使用错误号的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆