什么是线程安全函数?

来源:互联网 发布:知彼手机定位怎么样 编辑:程序博客网 时间:2024/04/30 18:44

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


        看看维基百科:

   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可重入,线程安全


   累了,喝口水,洗澡去。

0 0
原创粉丝点击