Originally Posted by
BENCHMARKMAN
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.