[Linux] Thread safety and reentrant functions __oracle

Source: Internet
Author: User
Thread Safety: a function is called thread-safe, and it always produces the correct result when and only if it is repeatedly invoked by multiple concurrent processes. If a function is not thread-safe, we say it is thread-unsafe. reentrant: The function is called by a different control flow, and it is possible to enter the function again when the first call has not returned; non-reentrant function: A function accesses a global list, which may cause confusion because of the reentry; Reentrant functions: If a function accesses only its own local variables or parameters, a reentrant function avoids thread-unsafe problems caused by access to other functions. Functions that can be reentrant are thread-safe.

As with global linked lists, it is possible to insert errors caused by a thread's problem while inserting two nodes at the same time, which causes the thread to be unsafe because its operation is not atomic and thus causes different actions to occur at the same time.

As in the example above, it is possible to have a dislocation caused by a reentrant, which is called a non reentrant function. we know that the reentrant function is a thread-safe function. If a function can be reentrant when multiple threads are said, this function is said to be thread safe. This does not mean that the function can be reentrant for a signal handler. If the function is safe for the reentry of the program at the asynchronous signal, it is said that the function is safe for the asynchronous signal. in general, a reentrant function is a thread-safe function, but a thread-safe function is not necessarily a reentrant function. use a picture to show it ~

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.