为什么在使用线程编译C代码时编写-D_REENTRANT [英] Why do we write -D_REENTRANT while compiling C code using threads

查看:37
本文介绍了为什么在使用线程编译C代码时编写-D_REENTRANT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们编译一个在其中实现了线程的C程序时,我们会写此语句.我不明白为什么我们在这里使用-D_REENTRANT.例如 gcc t1.c -lpthread -D_REENTRANT

We write this statement when we are compiling a C program that has threads implemented in them. I could not understand why we use -D_REENTRANT here. e.g gcc t1.c -lpthread -D_REENTRANT

推荐答案

您不必编写它.但这是推荐的.

You don't have to write it. But it is recommended.

定义_REENTRANT 使编译器使用C库中多个函数的线程安全(即可重入)版本.

Defining _REENTRANT causes the compiler to use thread safe (i.e. re-entrant) versions of several functions in the C library.

这篇关于为什么在使用线程编译C代码时编写-D_REENTRANT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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