2 #include <cds/sync/spinlock.h>
12 cds::sync::spin_lock<cds::backoff::LockDefault> mutex;
15 for (int i = 0; i < 100000; i++) {
16 for (int j = 0; j < 3000; j++) {
17 // for (int i = 0; i < 300000; i++) {
18 // for (int j = 0; j < 300000; j++) {
19 if (!mutex.is_locked()) {
22 y.load(memory_order_relaxed);
30 const int kThreads = 6;
31 cout << "Starting " << kThreads << " threads for Spinlock...\n";
33 struct timespec start, finish;
35 clock_gettime(CLOCK_MONOTONIC, &start);
37 std::thread threads[kThreads];
38 for (int i = 0; i < kThreads; i++) {
39 threads[i] = std::thread(Thread);
42 for (int i = 0; i < kThreads; i++) {
45 clock_gettime(CLOCK_MONOTONIC, &finish);
46 elapsed = (finish.tv_sec - start.tv_sec);
47 elapsed += (finish.tv_nsec - start.tv_nsec) / 1000000000.0;
48 cout << "All threads finished.\n";
49 cout << "Time: " << elapsed << " seconds\n";