前面,我们讲了可重入函数,现在看看线程安全函数。首先,我们来欣赏一幅图吧:


        看看维基百科:

   Thread safety is a computer programming concept applicable in the context of multi-threaded programs. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time.


   多的不说了,最后以strtok函数结尾本文(参照上图):

   1. strtok不可重入,线程不安全

   2. 加锁的strtok不可重入,但线程安全

   3. strtok_r可重入,线程安全


   累了,喝口水,洗澡去。


本文转载:CSDN博客