Full text See http://www.eefocus.com/article/09-04/71618s.html
The central idea is:
thread-safe functions: Generally speaking, a function is called thread-safe, and when and only repeatedly invoked by multiple concurrent threads, it always produces the correct result.
Reentrant: When a program executes to a function foo (), receives the signal, then pauses the currently executing function, goes to the signal processing function, and this signal processing function's execution process, also will enter the function foo () which just executes, thus has the so-called reentrant. if Foo () is able to run correctly, and after processing completes, the previously paused foo () can run correctly, then it can be reentrant.
Summarize:
-If a function uses a global or static variable, then it is not thread-safe, nor can it be reentrant;
-If we improve on it, when you access a global or static variable by using a lock such as a mutex or semaphore, you can make it thread-safe, but it is still not reentrant, because it is usually locked for access to different threads and may cause problems for the same thread;
-If you remove the global or static variables from the function, and change them into other forms such as function arguments, it is possible to make the function both thread-safe and reentrant.