是< stdlib.h>中提供的malloc()函数吗?线程安全的? [英] Is malloc() function provided in <stdlib.h> thread-safe?

查看:206
本文介绍了是< stdlib.h>中提供的malloc()函数吗?线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有没有人对malloc()的线程安全问题有经验?

有人说stdlib.h中提供的这个函数不是线程 -

安全,但有人说它是线程安全的。近年来,这个

函数是否有可能从线程不安全发展到线程安全?

我怎么能找到答案?

我是使用随GNU linux发行的C库。


非常感谢。


tony

Hi all,
Does anyone have experience on the thread-safty issue with malloc()?
Some people said this function provided in stdlib.h is not thread-
safe, but someone said it is thread safe. Is it possible this
function evolves from thread-unsafe to thread-safe in recent years?
How could i find out?
I am using the C library coming with GNU linux distribution.

thanks a lot.

tony

推荐答案

在文章< b8 ********************************** @ 27g2000hsf.g ooglegroups.com>,

< cl ********* @ gmail.comwrote:
In article <b8**********************************@27g2000hsf.g ooglegroups.com>,
<cl*********@gmail.comwrote:

有没有人对malloc()的线程安全问题有经验?
有些人说stdlib.h中提供的这个函数不是线程安全的,但是有人说它是线程安全的。近年来,这个功能是否有可能从线程不安全发展到线程安全?
我怎么能找到答案?
Does anyone have experience on the thread-safty issue with malloc()?
Some people said this function provided in stdlib.h is not thread-
safe, but someone said it is thread safe. Is it possible this
function evolves from thread-unsafe to thread-safe in recent years?
How could i find out?



C标准没有线程或线程安全的概念,所以

除非你用空虚定义线程,否则必须假设/>
将是malloc()不是*线程安全的平台。

The C standards have no concept of threads or thread safety, so
unless you define threads vacuously, one must assume that there
will be platforms on which malloc() is *not* thread safe.


我正在使用随GNU linux发行版的C库。
I am using the C library coming with GNU linux distribution.



如果你想知道malloc()在您使用的

特定发行版中是否是线程安全的,那么请询问新闻组

或处理该特定发行版的邮件列表。

C作为一个整体的答案是否。可能是您感兴趣的所有平台的答案都是是,但

可能是由于特定于实现的行为,而不是行为<由C.授权的


-

对于男人来说,他们很容易沿着小腿路径盲目地走向

介意做别人做过的事。他们沿着殴打的b
轨道进出,然后进出,进出,然后他们继续追求,以保持其他人所做的道路。 - Sam Walter Foss

If you want to know about whether malloc() is thread-safe in the
particular distribution you are using, then ask in a newsgroup
or mailing list that deals with that particular distribution.
The answer for C as a whole is "NO". It could be that the
answer for all platforms that you are interested in is "Yes", but
that would be due to implementation-specific behaviour, not behaviour
mandated by C.
--
"For men are prone to go it blind along the calf-paths of the
mind To do what other men have done. They follow in the beaten
track, and out and in, and forth and back, and still their
devious course pursue, to keep the path that others do." -- Sam Walter Foss


cl ****** ***@gmail.com 写道:

大家好,

有没有人有线程安全问题的经验使用malloc()?

有些人说stdlib.h中提供的这个函数不是thread-

安全,但是有人说它是线程安全的。近年来,这个

函数是否有可能从线程不安全发展到线程安全?

我怎么能找到答案?

我是使用随GNU linux发行的C库。
Hi all,
Does anyone have experience on the thread-safty issue with malloc()?
Some people said this function provided in stdlib.h is not thread-
safe, but someone said it is thread safe. Is it possible this
function evolves from thread-unsafe to thread-safe in recent years?
How could i find out?
I am using the C library coming with GNU linux distribution.



然后检查你的手册页。


-

Ian Collins。

Then check your man pages.

--
Ian Collins.


在comp.lang.c中, cl ********* @ gmail.com 写道:
In comp.lang.c, cl*********@gmail.com wrote:

大家好,

有没有人对malloc()的线程安全问题有经验?
Hi all,
Does anyone have experience on the thread-safty issue with malloc()?



可能。在任何情况下,线程安全指的是线程安全。这里无关紧要。 C标准

不包括线程,并且不解决特定库

函数是否是线程安全的。或者不是。


但是,您的C编译器/实现/可以识别线程。在你的

环境中。要确定您的/实现/供应线程安全

标准库函数,您应该检查您的/ implementation'/

文档或询问相关主题在相应的/ implementation /

论坛。

Possibly. In any case, "thread-safety" is irrelevant here. The C standard
does not include "threads", and does not address whether a specific library
function is "thread-safe" or not.

However, your C compiler /implementation/ may recognize "threads" in your
environment. To determine if your /implementation/ supplies "thread-safe"
standard library functions, you should check your /implementation''s/
documentation or ask about the subject in the appropriate /implementation/
forum.


有人说stdlib.h中提供了这个函数
Some people said this function provided in stdlib.h



stdlib.h不提供任何功能。它提供函数声明

(函数的调用参数和返回值的原型),

宏和其他类型的信息。 / function /将在

中提供一个实现的库。

stdlib.h does not provide any function. It provides function declarations
(prototypes for the function''s calling parameters and return value),
macros, and other sort of information. The /function/ will be provided in
one of your implementation''s libraries.


不是线程安全的,但有人说它是线程安全的。
is not thread-safe, but someone said it is thread safe.



有些人 "有人" ;?请问实施者,或检查

实施文档怎么样?请记住,即使在这里,我们也是某些人,

而我是某人。

"Some people" "Someone"? How about asking the implementers, or checking the
implementation documentation? Remember, even here, we are "some people",
and I am "someone".


这可能吗? br />
函数近年来从线程不安全发展到线程安全吗?
Is it possible this
function evolves from thread-unsafe to thread-safe in recent years?



在任何具体实现中都是如此。一个实现甚至可以提供相同函数的线程安全和线程不安全版本,只要选择该函数的

机制不在C语言中(比如

编译器或链接器选项,或备用库的规范

在链接期间)。

It is, in any specific implementation. An implementation can even offer both
thread-safe and thread-unsafe versions of the same function, so long as the
mechanism that selects the function is outside of the C language (like a
compiler or linker option, or the specification of an alternate library
during linkage).


我怎么能找到?
How could i find out?



阅读编译器的文档。阅读运行时的文档。

Read your compiler''s documentation. Read the documentation on your runtime.


我正在使用随GNU linux发布的C库。
I am using the C library coming with GNU linux distribution.



< OT>

假设最新版本的GCC和最近的Linux实现,你

可能有

1)根本没有线程支持,

2)Linux线程支持,或

3)NPTL线程支持


Linux线程和NPTL线程运行时是在不同的
(非C标准)库中实现的,它们提供线程原始的

函数和(可能的)线程安全库。标准和POSIX库中某些

线程不安全函数的替换函数。

如果您的环境不包含Linux Threads和Linux Threads。或者NPTL
线程,那么你可能有一个C运行时库,它不能识别

个线程,因此有一个可疑的线程安全。 (函数/可能/是

线程安全,但不保证)。检查您的/ usr / doc / gcc *

文档,以及您打算使用的每个函数的联机帮助页,以及

查找有关如何使用相应线程的说明图书馆。

< / OT>

<OT>
Assuming a recent version of GCC and a recent implementation of Linux, you
have may have
1) no threading support at all,
2) "Linux threads" support, or
3) "NPTL" threads support

"Linux Threads" and "NPTL threads" runtimes are implemented in different
(non-C-standard) libraries, which provide both the threading primative
functions and (possibly) "thread-safe" replacement functions for some
thread-unsafe functions in the standard and POSIX libraries.

If your environment does not include either "Linux Threads" or "NPTL"
threads, then you likely have a C runtime library that does not recognize
threads, and thus has a questionable "thread-safety" (functions /may/ be
thread-safe, but there is no guarantee). Check your /usr/doc/gcc*
documentation, and the manpage for each function you intend to use, and
look for the instructions on how to use the appropriate threading library.
</OT>


非常感谢。


tony
thanks a lot.

tony



-

Lew Pitcher


Master Code代理& JOAT-in-training |已注册的Linux用户#112576
http://pitcher.digitalfreehold.ca/ |可根据要求提供GPG公钥

---------- Slackware - 因为我知道我在做什么。 ------

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I''m doing. ------


这篇关于是&lt; stdlib.h&gt;中提供的malloc()函数吗?线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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