Understanding of Data race free

Source: Internet
Author: User
Motivation for data race free

Data race free is a description of the degree of synchronization of multi-threaded programs. If the degree of synchronization of your multi-threaded programs meets the requirements of DRF, your program will have the following benefits:

The program is executed in the weak consistency model, and the execution result is the same as that in the SC model.

This means that when a programmer writes a program, he can deduce the execution of the program according to the SC model. While the program runs at the underlying layer, it can enjoy various optimization measures brought about by the weak consistency model.

Data race free content

DRF requires that multi-threaded programs do not have conflicting operations.

What are conflicting operations?

Conflicting operations refer to two operations that come from different threads and operate on the same address. At least one operation is a write operation.

How can we avoid conflicting operations?

You need to use synchronization operations to isolate conflicting operations.

Why do I need to isolate conflicting operations with synchronization operations?

If the program is not isolated, the execution results in the weak consistency model are different from those in the SC model. This means that if you use the SC Model to deduce the program execution results, and the program runs under the weak consistency model, the actual results of the program may be different from what you infer.

So why: if the program is not isolated, the execution results in the weak consistency model are different from those in the SC model?

This is actually a question: why does isolation make the execution result of the program in the weak consistency model consistent with that in the SC Model?

The answer to this question is: Isolation allows us to find a full sequence of all operations, which is exactly what SC needs.

Synchronization operations will isolate conflicting operations, which adds some order to the unordered multi-threaded program:

  • The synchronization operations are ordered.
  • The synchronization operation is in sequence with all previous operations.
  • The synchronization operation is sequential with all subsequent operations.

These sequences ensure that the program runs the same results in the weak consistency model as in the SC model.

In addition, we also found that there is no sequence guarantee between some operations, which is the advantage of DRF. These operations without sequence assurance can be optimized under the weak consistency model, at the same time, their unordered execution results will not be any different from those in SC.

If we want to find a full sequence between all operations, we only need to select an order among these operations that do not need to be ordered. In addition, you also need to ensure the sequence relationships added due to synchronization. This constitutes a full order. This full order is exactly what the SC Model needs.

As a result, we also understand the essence of DRF:

Only ensure the necessary order, not the unnecessary order.

It is necessary to ensure that the execution results of the program in the weak consistency model are consistent with those in the SC model.

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.