reentrant functions and thread-safe functions __ functions

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.