Subj : How to ensure that a thread runs while another is doing I/O To : comp.programming.threads From : Anant Padmanath Mudambi Date : Sun Jan 09 2005 07:56 pm Hi all, Consider this psuedo code: M1,M2 : mutexes C: condition variable thread_1 { mutex_lock(M1); mutex_lock(M2); create thread_2; cond_wait(C, M1); mutex_unlock(M1); mutex_unlock(M2); big write to a file on disk; join(thread_2); } thread_2 { mutex_lock(M1); CPU-bound work #1; mutex_unlock(M1); cond_signal(C); mutex_lock(M2); CPU-bound work #2; } By putting printf()s in this code I saw that after thread_2 signals C, sometimes the "CPU-bound work #2" executes while thread_1 is waiting for the file write to finish and sometimes it executes AFTER the whole file write finishes. How can I ensure that thread_2 always continues to execute as soon as possible without waiting for the whole file write in thread_1 to finish? Assume these are the only 2 user threads on the system. Thank you, Anant. .