Listing 14: (a) RTLinux contested spinlock test; (b) RTLinux contested spinlock output.

(a)
Thread A
   pthread_spin_lock(&lock);
   sem_post(&sem);
   clock_gettime(CLOCK_REALTIME, &start);
   pthread_spin_unlock(&lock);
Thread B
   sem_wait(&start_sem);
   pthread_spin_lock(&lock);
   clock_gettime(CLOCK_REALTIME, &end);
   pthread_spin_unlock(&lock);

(b)
Contested Spinlock Acquisition: (96h 0m 0s test)
38.5 us