------- Comment #19 from tstarling at wikimedia dot org 2010-09-09 14:28 ------- (In reply to comment #16) > The *_unlocked versions are faster a lot actually, at least for the one > character ops, because no locking is performed and the calls are inlined. > But the question is whether libstdc++ can use them, unless there is some > restriction that would disallow several threads from using the same FILE * > (including using STL APIs in one thread and C stdio APIs in another thread).
My current idea is to do: flockfile(stdin); while (!eof) { c = getc_unlocked(stdin); ... } funlockfile(stdin); This is not only much faster, it's an improvement to the current behaviour in terms of locking and thread safety. The current behaviour, as I said in comment #4, could cause data to be badly mangled if one thread uses stdio while another uses cin.getline(). Using getc() in preference to getc_unlocked() does not help. And unlike getdelim(), the unlocked I/O functions are in POSIX.1-2001, says the man page, so it's relatively portable. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45574