strtok 函数线程安全 [英] strtok function thread safety
本文介绍了strtok 函数线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我花了一些时间调试一个导致分段错误的程序.该错误非常不确定且断断续续,这很烦人.我将范围缩小到 strtok()
的调用.我怀疑是调用 strtok()
在两个不同的线程中拆分字符串导致了分段错误.我可以在两个不同的线程中调用 strtok()
吗?
I have been spending some time in debugging a programme which gives segmentation fault. The bug is quite indeterministic and intermittent, which is annoying. I narrowed it down to the calling of strtok()
. I suspect that it is the calling of strtok()
to split string in two different threads that causes the segmentation fault. Can I call strtok()
in two different threads?
谢谢.
推荐答案
strtok()
不可重入,因此不应在线程应用程序中使用它,请使用 strtok_r()
代替.
strtok()
is not reentrant so it should not be used from threaded applications, use strtok_r()
instead.
这篇关于strtok 函数线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文