Parallel computing — jumbled up output?

后端 未结 2 774
别跟我提以往
别跟我提以往 2020-12-11 05:51

I\'m trying to learn the basics of parallel computing, but I\'m running into an issue on my computer. Take a look at my code below. Basically, I want to print out the line &

2条回答
  •  天命终不由人
    2020-12-11 06:15

    Sorry, your professor's mistaken. You need to leverage mutual exclusion or some other barriers in order to guarantee uninterrupted use of a shared resource (which in this case is the STDOUT output file).

    Mixed output is potential expected behavior regardless of printf or std::cout::operator<<(). The differences in behavior you see are subtle differences in the execution duration of each, due to their differing design. You should expect this behavior in either case.

    I just don't understand why it would be working for everyone else.

    It's not. Be a hero to your class and explain how it works and how to fix it. Tell them SO sends their love. :)

提交回复
热议问题