The code logic of Example 6-8 is incorrect:
"if (__TM_begin (TM_buff))" should be "if (__TM_begin (TM_buff) == 0)", since __TM_begin return value 0 means transaction successfully begin.
non-zero value means transaction failed.
Example 6-8 Complex HTM usage using portable HTM intrinsics
if (__TM_begin (TM_buff))
/* Transaction State Initiated. */
if (is_locked (lock))
a = b + c;
/* Transaction State Failed. Use locks if the transaction
Posted by Karen Lawrence on 9 May 2014 at 9:20
We will follow up on this for you. Thank you for your comment.
Posted by Dr. Peter Bergner on 12 May 2014 at 9:51
The example in the document is correct. The HTM builtins and intrinsic functions were all designed to return non-zero values on success and zero otherwise.
I think your confusion is due to the .tbegin hardware instruction setting of CR0's Zero/EQ bit on transaction failure. Buitins and other functions can only return values via normal "types" and no type maps directly to CR registers, we had to synthesize a normal source level return value from CR0's Zero/EQ bit and non-zero means success.