Not sure what pthread provides, but grab a mutex lock or semaphore before doing any screen output. That way you can ensure that only one thread can print at a time. Note that this means you shouldn't be doing print statements in the middle of computation, since the lock will serialize that part of the code.