What if _xbegin(); leads to a segmentation fault?

51 views Asked by At

I'm trying to compile the following TSX sample code on an Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz that supports TSX using gcc tsc.x -mrtm:

#include <immintrin.h>
#include <stdio.h>

int max_tries=100;
unsigned status = _XABORT_EXPLICIT;


int main(){

    for (int n_tries = 0; n_tries < max_tries; n_tries++) 
    {
        status = _xbegin();
        if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY))
        {
                break;
        }

        if(status == _XBEGIN_STARTED) 
        {
                printf("TSX started\n");
                _xend ();
        } 
        else 
        {
            printf("TSX failed\n");
        }

    }


return 0;
}

But the output would either result into "Illegal instruction (core dumped)" or simply no output and in rare cases TSX failed. But never TSX started.

0

There are 0 answers