Go backward to Standard Input Go up to Restrictions Go forward to C++ Memory Allocation |
If only one thread writes to standard output, it suffices to bind the thread to any process
The main thread (which is bound to the initial process) need not take any provisions at all.rt_bind(); cout << "data " << data << "{n"; rt_unbind();
However, if multiple threads write to standard output, it does not suffice to bind a thread to a specific process. We also have to guarantee that the process is not interrupted while performing the output operation, because otherwise another thread might interfere with its own output. Thus every thread (also the main thread) has to protect its output operations as follows
The output sequences generated by threads on different processors are non-deterministically merged on the output device.rt_lock(); cout << "data " << data; rt_unlock();