/
BirdLeon
/
ROBLOX2016
Обзор
Документация
Войти
/
BirdLeon
/
ROBLOX2016
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Library/boost/libs/thread/test/test_11499.cpp
55 строк
1009 B
PatoFlamejanteTV
full source code
19 дек 2024, 19:11
19 дек 2024, 19:11
05db15d
Код
Авторство
О чём код?
// Copyright (C) 2014 Vicente Botet // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #define BOOST_THREAD_VERSION 4 #include <boost/thread/shared_mutex.hpp> #include <thread> #include <mutex> #include <shared_mutex> #include <atomic> #include <vector> using MutexT = boost::shared_mutex; using ReaderLockT = std::lock_guard<MutexT>; using WriterLockT = std::shared_lock<MutexT>; MutexT gMutex; std::atomic<bool> running(true); void myread() { long reads = 0; while (running && reads < 100000) { ReaderLockT lock(gMutex); std::this_thread::yield(); ++reads; } } int main() { using namespace std; vector<thread> threads; for (int i = 0; i < 256; ++i) { threads.emplace_back(thread(myread)); } // string str; // // getline(std::cin, str); running = false; for (auto& thread : threads) { thread.join(); } return 0; }