Writing a single line for cout "thread safe" in C ++ 98

I know that, strictly speaking, in C ++ 98, nothing is thread safe, because there are no threads in the standard before C ++ 11. However, in practice, threads were used in C ++ long before C ++ 11.

So, let's say two pthreadssimultaneously call this:

void printSomething(){
    std::cout << "something\n";
}

What can lead to the alternation of two outputs? Or will I always get in practice two lines containing "something"?

I ask about this because this question made me wonder, and I found this answer by indicating:

... in C ++ 11, std :: cout is thread safe.

but this answer is an example along the line

std::cout << "aaaaaaaaaa" << "bbbbbbbbbb";

, ++ 98 , , , , operator<< .

+4
1

, ++ 98 , .

++ 98, (.. ), std::cout "" . , , .

, , . , , "" . , , , , , " ". , .

. , 1!

, , - (, - ) , std::cout. , .

, , , std::cout << "AAAA" 1 std::cout << "BBBB" 2, " " AAAABBBB BBBBAAAA, BBAAAABB - . , ! , , , , , .

, std::cout (.. operator<<(const char *) ), , , stdout, , std::cout - , printf().

C/++ , write(), . , ( , , , , ).

- . - std::cout << "AAA" << "BBB" ... std::cout. . , iomanip . - std::cout << std::hex << 123 << std::dec , , hex, . , , , - , .


1 , , libst++ ( gcc) lib++ ( LLVM , Linux). -, Microsoft C-.

+6

Source: https://habr.com/ru/post/1687755/


All Articles