\"\" \"\" \"\"
Go backward to Standard Input
Go up to Restrictions
Go forward to C++ Memory Allocation
RISC-Linz logo

Standard Output

The memory buffers associated to the standard output stream are allocated in the data segment of a process. Unlike reading from the standard input stream , the standard output stream may be written by any process, since the buffers of all processes are flushed to the same output device.  

If only one thread writes to standard output, it suffices to bind the thread to any process   

rt_bind();
cout << "data " << data << "{n";
rt_unbind();
The main thread (which is bound to the initial process) need not take any provisions at all.

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   

rt_lock();
cout << "data " << data;
rt_unlock();
The output sequences generated by threads on different processors are non-deterministically merged on the output device.
Author: Wolfgang Schreiner
Last Modification: April 12, 1997