Take the following code using thread_local variable as an example:
void func() {
thread_local int a;
......
}
According to Wikipedia, I know it is a thread_safety function. But should we call it also a re-entrant function?
Take the following code using thread_local variable as an example:
void func() {
thread_local int a;
......
}
According to Wikipedia, I know it is a thread_safety function. But should we call it also a re-entrant function?
Thread safety != re-entrancy.
A re-entrant function can be interrupted (by an interrupt or signal handler, say) and then re-entered by that signal handler; this happens in one thread.
We wouldn't be able to tell whether func()
is re-entrant or not solely from the fact that it uses one thread-local variable.
To make a long story short: If a function accesses global data in a non-atomic way (or calls a function that does so), then it's non-reentrant. This doesn't necessarily involve threading at all.