g_pages:std::map<std::string,std::string>=();g_pages_mutex:std::mutex=();save_page:(url:std::string)={// simulate a long page fetchstd::this_thread::sleep_for(std::chrono::seconds(2));result:conststd::string="fake content";_:std::lock_guard=(g_pages_mutex);g_pages[url]=result;}main:()={t1:std::thread=(save_page,"http://foo");t2:std::thread=(save_page,"http://bar");t1.join();t2.join();// safe to access g_pages without lock now, as the threads are joinedforg_pagesdo(pair)std::cout<<"(pair.first)$ => (pair.second)$\n";}