Writing from multiple threads in the same task

If you are writing to a TTieredTextBuffer from multiple threads in the same task concurrently, the messages from different threads can be intermingled. You must use a TChunkyTieredTextBuffer object to keep output from each thread together. A TChunkyTieredTextBuffer object accumulates output text until it is destroyed or until you call Flush, when it dumps its output in a single chunk to
its parent.

    1      TChunkyTieredTextBuffer buffer(OutputTextStream());
    2      buffer.PushTier(TTieredText::kGeneral);
    3      buffer << "TSampleObjectBaseTest::Test()\n";
    4      buffer.PushTier(TTieredText::kNormal);
    5      buffer << "    fTextOption = ";
    6  
    7              if (fTextOption)
    8          buffer << *fTextOption;
    9      else
    10          buffer << "NIL";
    11      buffer << "\n";
    12      buffer << "    TextInBuffer = " << TextInBuffer << "\n";
    13      buffer << "    myText2 = " << myText2 << "\n";
    14      buffer.PopTier();
    15      buffer.PopTier();
    16      // You can flush the buffer at any time by calling Flush
    17      buffer.Flush();
Line number 1 creates the TChunkyTieredTextBuffer object.

Line number 2 sets the tier to General for subsequent lines.

Line number 4 sets the tier to Normal for subsequent lines.

Line number 14 pops the tier back to General.

Line number 15 pops the tier back to the level set before line 2.

When you destroy the buffer object, all of the text is flushed to the object's parent. If any other TChunkyTieredTextBuffer object is flushing its text, the thread containing buffer is blocked when the buffer object attempts to flush
its text.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker