|
发表于 2004-4-7 06:39:05
|
显示全部楼层
回复: pthread_self()的manual里的reentrant c library有什么用?
最初由 incarnation 发表
这里面的内容:
libc_r , -pthread
这个怎么用,这些基础我都不懂。。麻烦大家了。:rolleyes:
I assume that you have understood what pthread_self(void) to do. Then I am going to focus on the fundamental definitions of reentrant and XX_r
Three following sections we need to take a look at:
1.There is a whole set of library calls associated with threads, most of whose names start with pthread. To use these library calls we must define the macro_REENTRANT, include the file pthread.h and link with the threads library using -lpthread.
2.Actually re-entrant is a routine, and its code can be called more than once, either by different threads, or called by nested invocations in some way, and still function correctly. Thus usually the reentrant section of code must only use local variables, in such a way that each and every call to the code gets its own unique copy of the data.
3. In multithreaded programs, we tell the compiler that we need this feature by defining the macr_REENTRANT before any #include lines in our program. This does three things for us, and does them so elegantly that usually we don't even need to know what was done. Some functions get prototypes for a reentrant safe equivalent. These are normally the same function name, but with _r appended so that , for example, gethostbyname is changed to gethostbyname_r. Some stio.h functions that are normally implemented as macros become proper re-entrant safe functions. Therefore, libc_r actually is the re-entrant safe form of libc.
Hopefully the explanation above could help you to have a basic background somehow. |
|