9 // Make sure that flags and wait sit in different cache lines
10 volatile int flags
[10];
11 volatile int wait
[10];
13 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
15 void *DoWork1(void *threadid
)
17 flags
[0] = flags
[0] + 1;
22 void *DoWork2(void *threadid
)
24 pthread_mutex_lock (&mutex
);
25 flags
[0] = flags
[0] + 1;
26 pthread_mutex_unlock (&mutex
);
30 ////////////////////////////////////////////////////////////////////////////////
32 ////////////////////////////////////////////////////////////////////////////////
33 int main( int argc
, char** argv
)
38 // initialize global variables
42 // monitor (via gcc intrinsic)
43 __builtin_ia32_monitor ((void *)&flags
, 0, 0);
45 // invalidate flags in this cpu's cache
46 pthread_create(&threads
[0], NULL
, DoWork1
, NULL
);
49 // launch thread to invalidate address being monitored
50 pthread_create(&threads
[0], NULL
, DoWork2
, NULL
);
52 // wait for other thread to modify flags
55 pthread_mutex_lock (&mutex
);
57 pthread_mutex_unlock (&mutex
);
58 __builtin_ia32_mwait(0, 0);
60 pthread_mutex_unlock (&mutex
);
63 } while (flags
[0] != 2 && mwait_cnt
< NUM_TRIES
);
65 // test may hang if mwait is not working
67 printf("mwait regression PASSED, flags[0] = %d\n", flags
[0]);
69 printf("mwait regression FAILED, flags[0] = %d\n", flags
[0]);