Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 8
    Using thread local doesn't solve the problems with strtok. strtok is broken even in a single threaded environment. Commented Aug 16, 2012 at 10:15
  • 20
    Sorry, let me rephrase that. It doesn't introduce any new problems with strtok :-) Commented Aug 16, 2012 at 10:16
  • 15
    Actually, the r stands for "re-entrant", which has nothing to do with thread safety. It's true that you can make some things work thread-safely with thread-local storage, but you can't make them re-entrant. Commented Aug 16, 2012 at 10:18
  • 8
    In a single-threaded environment, functions need to be re-entrant only if they are part of a cycle in the call graph. A leaf function (one that doesn't call other functions) is by definition not part of a cycle, and there is no good reason why strtok should call other functions. Commented Aug 16, 2012 at 12:39
  • 7
    this would mess it up: while (something) { char *next = strtok(whatever); someFunction(next); // someFunction calls strtok } Commented Jun 25, 2014 at 20:18