Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/MySQL/unsupported/test/   (MySQL Server Version 8.1-8.4©)  Datei vom 12.11.2025 mit Größe 1 kB image not shown  

Quelle  cxx11_tensor_notification.cpp   Sprache: C

 
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2015 Vijay Vasudevan <vrv@google.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#define EIGEN_USE_THREADS

#include <atomic>

#include <stdlib.h>
#include "main.h"
#include <Eigen/CXX11/Tensor>

static void test_notification_single()
{
  ThreadPool thread_pool(1);

  std::atomic<int> counter(0);
  Eigen::Notification n;
  auto func = [&n, &counter](){ n.Wait(); ++counter;};
  thread_pool.Schedule(func);
  std::this_thread::sleep_for(std::chrono::milliseconds(1000));

  // The thread should be waiting for the notification.
  VERIFY_IS_EQUAL(counter, 0);

  // Unblock the thread
  n.Notify();

  std::this_thread::sleep_for(std::chrono::milliseconds(1000));

  // Verify the counter has been incremented
  VERIFY_IS_EQUAL(counter, 1);
}

// Like test_notification_single() but enqueues multiple threads to
// validate that all threads get notified by Notify().
static void test_notification_multiple()
{
  ThreadPool thread_pool(1);

  std::atomic<int> counter(0);
  Eigen::Notification n;
  auto func = [&n, &counter](){ n.Wait(); ++counter;};
  thread_pool.Schedule(func);
  thread_pool.Schedule(func);
  thread_pool.Schedule(func);
  thread_pool.Schedule(func);
  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  VERIFY_IS_EQUAL(counter, 0);
  n.Notify();
  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  VERIFY_IS_EQUAL(counter, 4);
}

EIGEN_DECLARE_TEST(cxx11_tensor_notification)
{
  CALL_SUBTEST(test_notification_single());
  CALL_SUBTEST(test_notification_multiple());
}

100%


¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.