Subj : Re: printf with thread To : borland.public.cpp.borlandcpp From : gary Date : Fri Nov 14 2003 11:30 am alas, printf(), like many C lib functions, is not reentrant, therefore if you call it from multiple threads it is only a matter of time before two instances of printf() calls step on each others' toes. one way to handle this is to write an output function, say thread_printf(), to use in place of printf() that simply writes the string output to a buffer and then printf() the buffer from a single thread that alone is allowed to call printf(). one (particularly dreadful) caveat here is that sprintf() is also non-reentrant, so you won't be able to format the strings you put in the buffer using C library functions. you'll have to include your own formating code in your output function. :gary abhimanyu wrote: > I m writing a program in which i m creating multiple > thread in which i m printing something using printf. Now > when i run that program after some time it hang without > any error, but if i comment out the printf statement it is > running fine. I wnat to ask if there is some problem using > printf with the threads, and is printf is thread safe. Plz > help me. > > Thanks in advace > Abhimanyu > .