• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/examples/quickstart/simple_future_continuation.cpp
1
//  Copyright (c) 2007-2024 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/execution.hpp>
8
#include <hpx/future.hpp>
9
#include <hpx/init.hpp>
10
#include <hpx/runtime.hpp>
11
#include <hpx/thread.hpp>
12

13
#include <iostream>
14

15
int get_id(int i)
×
16
{
17
    return i;
×
18
}
19

20
int func1()
3✔
21
{
22
    std::cout << "func1 thread id: " << hpx::this_thread::get_id() << std::endl;
3✔
23
    return get_id(1) ? 123 : 0;
3✔
24
}
25

26
// this continuation function will be executed by an HPX thread
27
int cont1(hpx::future<int> f)
2✔
28
{
29
    std::cout << "cont1 thread id: " << hpx::this_thread::get_id() << std::endl;
4✔
30
    std::cout << "Status code (HPX thread): " << f.get() << std::endl;
2✔
31
    std::cout << std::flush;
32
    return 1;
2✔
33
}
34

35
// this continuation function will be executed by the UI (main) thread, which is
36
// not an HPX thread
37
int cont2(hpx::future<int> f)
1✔
38
{
39
    std::cout << "Status code (main thread): " << f.get() << std::endl;
1✔
40
    return 1;
1✔
41
}
42

43
int hpx_main()
1✔
44
{
45
    // executing continuation cont1 on same thread as func1
46
    {
47
        hpx::future<int> t = hpx::async(&func1);
48
        hpx::future<int> t2 = t.then(hpx::launch::sync, &cont1);
1✔
49
        t2.get();
1✔
50
    }
51

52
    // executing continuation cont1 on new HPX thread
53
    {
54
        hpx::future<int> t = hpx::async(&func1);
55
        hpx::future<int> t2 = t.then(hpx::launch::async, &cont1);
1✔
56
        t2.get();
1✔
57
    }
58

59
    // executing continuation cont2 on UI (main) thread
60
    {
61
        hpx::execution::experimental::main_pool_executor exec;
62
        hpx::future<int> t = hpx::async(&func1);
63
        hpx::future<int> t2 = t.then(exec, &cont2);
1✔
64
        t2.get();
1✔
65
    }
66

67
    return hpx::local::finalize();
1✔
68
}
69

70
int main(int argc, char* argv[])
1✔
71
{
72
    return hpx::local::init(hpx_main, argc, argv);
2✔
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc