weird output when I use pthread and printf

后端 未结 5 1066
执念已碎
执念已碎 2020-12-19 11:57

I write a program using pthread.

Environment:windows 7 , CYGWIN_NT-6.1 i686 Cygwin , gcc (GCC) 4.5.3

The source code

#include<         


        
5条回答
  •  不思量自难忘°
    2020-12-19 12:40

    Just because a function is thread-safe, it doesn't mean it's atomic.

    In your case, if you want to ensure that your output don't get interleaved, you need to use a mutex to ensure that only one thread calls printf at a time.

提交回复
热议问题