strtok的功能线程安全 [英] strtok function thread safety

查看:467
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆