Dumb I/O Performance Question

This is a discussion on Dumb I/O Performance Question within the C Programming forums, part of the General Programming Boards category; Visual Studio provides several versions of standard CRT library, Multi-threaded versions have internal locking in the IO functions...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Visual Studio provides several versions of standard CRT library, Multi-threaded versions have internal locking in the IO functions
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #17
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    Quote Originally Posted by BENCHMARKMAN View Post
    Efficencly is actually a secondary effect of what I am trying to accomplish. I'm creating 20 thread that print debut and using multiple printf statments causes the output to be interleaved.
    If you must use the same output stream, and you want to stop interleaving, you can serialize them via a global mutex and use fflush():

    Code:
            /* body of individual thread */
            pthread_mutex_lock(&output_mutex);
            fprintf(stdout, "individual thread output 1\n");
            fprintf(stdout, "individual thread output 2\n");
            fprintf(stdout, "individual thread output 3\n");
            fprintf(stdout, "individual thread output 4\n");
            fflush(stdout);
            pthread_mutex_unlock(&output_mutex);
    I wouldn't even waste time looking for this to be a significant bottleneck either, unless you're pumping out lots of output - and if you are, you're hitting other locks anyways.

  3. #18
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    better yet - implement some queue and loggerThread

    All threads post their logs to queue (using appropriate locking)
    One thread - does nothing except reading from the queue and printing messages
    This will prevent blocking working threads due to IO delays
    On the other hand loggerThread will be mostly waiting for IO operation complition without using to much CPU
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #19
    Registered User
    Join Date
    Apr 2006
    Posts
    47
    Thanks for the replies. I didn't really want to use a mutex becaues the printf() is already in a locked section.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. very dumb question.
    By Blips in forum C++ Programming
    Replies: 14
    Last Post: 11-08-2005, 08:37 AM
  2. Dumb question
    By dragon2309 in forum C Programming
    Replies: 18
    Last Post: 10-29-2005, 03:27 PM
  3. C++ File I/O question
    By zero_cool in forum C++ Programming
    Replies: 3
    Last Post: 08-16-2005, 10:43 AM
  4. File I/O Question
    By Sentral in forum C++ Programming
    Replies: 4
    Last Post: 07-06-2005, 04:49 AM
  5. dumb question...
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-28-2002, 10:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21