From: James S. <jam...@op...> - 2007-02-14 22:04:37
|
On Tue, 2007-02-13 at 22:10 -0800, Brian Dessent wrote: > James Steward wrote: > > > If a threaded app is written in C where there's no exception handling, > > it shouldn't be a problem, right? > > I'm not sure. But I did notice that if _MT is not defined then stdio.h > selects faster non-threadsafe versions of getc, putc, getchar, and > putchar. So using those functions in a multithreaded C application > without -mthreads would be a possible example of such a case. I didn't > see any other obvious uses of _MT but I didn't really look that hard. Curious. I believe the OP uses g++, threads, linked static? However I'd like to know whether there is any impact of this for my situation, gcc, threads, linked dynamic. I built both my test app and dll with and without -mthreads and diffed the objdump -D output. There were a few differences (say about 6 lines) even though I do not directly use any of the functions that may differ in stdio.h depending on whether _MT is defined or not (see below). I do use fgets. Could that call getc? Otherwise I wonder why gcc creates differences in the compiled code? Also, the thread cleanup helper dll was not in the list according to objdump -p of the -mthreads built version, so it must be a g++ thing only? I guess so long as one thread only accesses a file using the non thread safe versions of the functions (below) there would be no danger of corruption. Regards, James. #if !defined _MT __CRT_INLINE int __cdecl getc (FILE* __F) { return (--__F->_cnt >= 0) ? (int) (unsigned char) *__F->_ptr++ : _filbuf (__F); } __CRT_INLINE int __cdecl putc (int __c, FILE* __F) { return (--__F->_cnt >= 0) ? (int) (unsigned char) (*__F->_ptr++ = (char)__c) : _flsbuf (__c, __F); } __CRT_INLINE int __cdecl getchar (void) { return (--stdin->_cnt >= 0) ? (int) (unsigned char) *stdin->_ptr++ : _filbuf (stdin); } __CRT_INLINE int __cdecl putchar(int __c) { return (--stdout->_cnt >= 0) ? (int) (unsigned char) (*stdout->_ptr++ = (char)__c) : _flsbuf (__c, stdout);} #else /* Use library functions. */ _CRTIMP int __cdecl getc (FILE*); _CRTIMP int __cdecl putc (int, FILE*); _CRTIMP int __cdecl getchar (void); _CRTIMP int __cdecl putchar (int); #endif |