#include <iostream>
#include <thread>
#include <vector>
#include <atomic>

std::atomic_flag spinlock = ATOMIC_FLAG_INIT;

void thread_func()
{
    while(spinlock.test_and_set());
    std::cout << "thread_func() printing!" << std::endl;
    spinlock.clear();
}


int main()
{
    spinlock.test_and_set();
    
    std::vector<std::thread> threads;
    for(unsigned int i = 0; i < 10; ++i)
        threads.emplace_back(thread_func);
    spinlock.clear();
    
    for(auto& t : threads)
        t.join();
}