This is the mail archive of the
mailing list for the Cygwin project.
- From: Oleg Ostrozhansky <oleg at olegos dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 6 Apr 2004 23:43:53 -0500
- Subject: reentrant functions
I have a question about writing a multi-threaded program (using POSIX.1
threads) in Cygwin. "info libc" has a nice chapter about reentrancy,
which talks about _<func>_r reentrant variants for functions that are
not thread-safe. But when as an example I try using _gets_r(), I'm
getting a link error that this function does not exist:
~ $ gcc -g threadtest.c
/cygdrive/c/.../cc3s8dTu.o(.text+0xb4): In function `main':
threadtest.c:26: undefined reference to `__gets_r'
collect2: ld returned 1 exit status
I can't find it anywhere in the libraries. The prototype is in stdio.h,
so the compile step works. What do I need to do to make it work?
I've just updated to the latest Cygwin (1.5.9) and gcc (3.3.1), with no
change (running under Windows 2000 and Windows XP).
Here are a couple of other notes that I had while working on this:
- "info libc" mentions the use of struct _reent, and that it needs to be
initialized for each process (shouldn't it be "thread" here? As well
as in a few other places). Unfortunately it neglects to say how to
initialize it. I found _REENT_INIT and _REENT_INIT_PTR macros in
sys/reent.h. It seems that the first one needs to be used as
struct _reent thread_one = _REENT_INIT(thread_one);
- I don't understand this part, as a possible way of achieving
reentrancy (also from "info libc"):
2. Ensure that each thread of execution control has a pointer
to its own unique reentrancy structure in the global variable
`_impure_ptr', and call the standard library subroutines.
How is it possible for two threads sharing global variables have
the same global variable point to different structures? (reentrancy
is only an issue when address space is shared, right? so it isn't
possible to have separate _impure_ptr's, as I understand. What am
I understanding wrong?)
- Is it ok to use the regular functions, that use the global reentrancy
structure, in one thread (or at least until multiple threads are
created), and _<func>_r ones in the other ones?
- In stdio.h there is a typo where the comment says "Recursive versions of
the above." I believe it should say "Reentrant", not "Recursive".
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html