The emerging HTM (Hardware Transactional Memory) technology can reduce the extra overhead (i.e., Lock) during doing transactions. Recently years, Intel make its hardware solutions, RTM (Restricted Transactional Memory), is available as a mature commercial products. There are three main instructions: XBEGIN, XEND, and XABORT for supporting HTM. Intel Intrinsics library natively support such three software interfaces in C/C++.
To start/end the transactional code region, programmer should use XBEGIN/XEND
. The XABORT instruction allows programmers to abort the execution of an RTM region explicitly. The XABORT instruction takes an 8-bit
immediate argument that is loaded into the EAX register becoming available to software following an RTM abort.
A simple example is just like following codes.
Firstly, you should check whether your CPU platform is support RTM or not. Just run cat /proc/cpuinfo
, the answer is yes if rtm
is shown in the flags item. To compile such RTM codes, you should include the C header named immintrin.h
add an extra compiler flags -mrtm
A full descriptions of RTM’s APIs is available here