На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: Qraizer, Hsilgos
Страницы: (3) 1 2 [3]  все  ( Перейти к последнему сообщению )  
> Вопрос по работе std::promise и std::shared_future
    Цитата JoeUser @
    Неплохо бы тестовый пример еще.


    ну использовать вот так можно:
    ExpandedWrap disabled
      #include "Logger.h"
      #include <iostream>
      #include <thread>
      #include <vector>
      #include <algorithm>
       
      void Test(core::Logger& logger, const std::wstring& message)
      {
          int counter = 1;
          while (counter < 10000)
          {
              logger.Log() << core::log::warning << L" " << core::log::thread << L" " << message << L" counter: " << counter << std::endl;
              ++counter;
          }
      }
       
       
      int main()
      {
          core::Logger logger(L"main.log");
       
          std::wstring msg1 = L"This is message one";
          std::wstring msg2 = L"This is message two";
          std::wstring msg3 = L"This is message three";
       
          std::vector<std::thread> threads;
       
          threads.emplace_back(Test, std::ref(logger), std::ref(msg1));
          threads.emplace_back(Test, std::ref(logger), std::ref(msg2));
          threads.emplace_back(Test, std::ref(logger), std::ref(msg3));
       
          std::for_each(threads.begin(), threads.end(), [](auto&& item) { item.join(); });
       
          std::cout << "Done...";
          std::cin.get();
          return 0;
      }
    Сообщение отредактировано: Wound -
    0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
    0 пользователей:
    Страницы: (3) 1 2 [3]  все


    Рейтинг@Mail.ru
    [ Script execution time: 0,0252 ]   [ 17 queries used ]   [ Generated: 19.04.24, 09:12 GMT ]