Subj : Re: reentrant fwrite/fputc/etc ? To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Fri Nov 14 2003 12:54 pm I do not think any such list is published. The C and C++ language standards view threads as platform dependent items and do not address them. The answer to what is reentrant hinges upon the requester's definition of reentrant. I remember telling someone that fputs was reentrant only to have him reply that me it was not. He then showed code where two threads both wrote to the same file. The fact that in each of the two calls he passed the same data area (the same FILE*) to the function did diagnose him. His idea was that the function should somehow diagnose his error. A function is reentrant if it does not alter information specific to its being called which was saved outside of what provided by the caller. For instance, fprintf uses an internal buffer to assemble the string which will be written to the file and for performance reasons that internal buffer is not allocated for each call. Therefore fprintf is not reentrant as a call from one thread can alter information being assembled by a current instance invoked by a different thread. If a function is reentrant usually translates to if the function used static or global memory for buffers and/or status. A quick look at a function's source code should show if it does that. However a closer look at how it uses such items is required to be sure. fwrite, fputc and fputs should be reentrant. You have posted in the newsgroup for the old Borland C++ compiler. The current implementations do internal file locking when writing to a file. I do not have the 6 year old Borland C++ RTL sources on my machine so cannot speak of the versions you are using. If you have questions of reentrancy for a specific function then look at the source code for the function. If you still are not confident that it is reentrant then write a wrapper function for it which uses critical section calls. .. Ed > gary wrote in message > news:3FB5045A.5000709@cordelli.net... > > does anyone know if there is a reentrant version of fwrite(), fputc(), > fputs(), or other standard C lib file output function? either in the > Borland C libraries or some open source library somewhere? > > as an aside, the non-reentrancy problem of C lib functions is > somewhat annoying because i've never been able to find a > definitive list of which functions are and aren't reentrant. it > seems you just have to discover them ad hoc as you program > and watch your code crash. does anyone know if Borland > (or Microsoft or any other compiler vendor) bothers to > publish such a list for their C libraries? .