test/klib/synch/synch_1.cpp
// This test aggressively locks and unlocks the lock to see if both threads ever think they're locked at the same time.
This test aggressively locks and unlocks the lock to see if both threads ever think they're locked at the same time.
This test aggressively locks and unlocks the lock to see if both threads ever think they ' re locked at the same time .
TEST(KlibSpinlockTest, Spinlocks2)
{
  cout << "This test takes several seconds to complete." << endl;
  klib_synch_spinlock_init(main_lock);
  thread other_thread(test_2_second_part);
  const uint32_t cycles = 100000;
  for (uint32_t i = 0; i < cycles; i++)
  {
    klib_synch_spinlock_lock(main_lock);
    ASSERT_FALSE(thread_2_locked);
    thread_1_locked = true;
    test_spin_sleep(10000);
    thread_1_locked = false;
    ASSERT_FALSE(thread_2_locked);
    klib_synch_spinlock_unlock(main_lock);
  }
  other_thread.join();
}
TEST ( KlibSpinlockTest , Spinlocks2 ) { cout << " " << endl ; klib_synch_spinlock_init ( main_lock ) ; thread other_thread ( test_2_second_part ) ; const uint32_t cycles = 100000 ; for ( uint32_t i = 0 ; i < cycles ; i ++ ) { klib_synch_spinlock_lock ( main_lock ) ; ASSERT_FALSE ( thread_2_locked ) ; thread_1_locked = true ; test_spin_sleep ( 10000 ) ; thread_1_locked = false ; ASSERT_FALSE ( thread_2_locked ) ; klib_synch_spinlock_unlock ( main_lock ) ; } other_thread . join ( ) ; }
This test aggressively locks and unlocks the lock to see if both threads ever think they're locked at the same time.
This test aggressively locks and unlocks the lock to see if both threads ever think they ' re locked at the same time .