Hardware transactional memory intrinsics for i386. These allow to use memory transactions with RTM (Restricted Transactional Memory). For using HLE (Hardware Lock Elision) see x86 specific memory model extensions for transactional memory instead. This support is enabled with the -mrtm option.
A memory transaction commits all changes to memory in an atomic way, as visible to other threads. If the transaction fails it is rolled back and all side effects discarded.
Generally there is no guarantee that a memory transaction ever suceeds and suitable fallback code always needs to be supplied.
Start a RTM (Restricted Transactional Memory) transaction. Returns _XBEGIN_STARTED when the transaction started successfully (note this is not 0, so the constant has to be explicitely tested). When the transaction aborts all side effects are undone and an abort code is returned. There is no guarantee any transaction ever succeeds, so there always needs to be a valid tested fallback path.
#include <immintrin.h> if ((status = _xbegin ()) == _XBEGIN_STARTED) { ... transaction code... _xend (); } else { ... non transactional fallback path... }
Valid abort status bits (when the value is not _XBEGIN_STARTED
) are:
_XABORT_EXPLICIT
_xabort
. The parameter passed
to _xabort
is available with _XABORT_CODE(status)
_XABORT_RETRY
_XABORT_CONFLICT
_XABORT_CAPACITY
_XABORT_DEBUG
_XABORT_NESTED
Commit the current transaction. When no transaction is active this will fault. All memory side effects of the transactions will become visible to other threads in an atomic matter.