-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·35 lines (28 loc) · 962 Bytes
/
main.cpp
File metadata and controls
executable file
·35 lines (28 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
int main()
{
// Create a work contract group
bcpp::work_contract_group group;
// Start worker thread to process scheduled work contracts
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
});
// Create a work contract from the work contract group
auto contract = group.create_contract([]()
{
std::cout << "Hello, World! from Work Contract\n";
bcpp::this_contract::release(); // Release to async destroy this contract
});
// Schedule the contract
contract.schedule();
// Main thread waits for contract to be released
while (contract.is_valid()) {}
// Signal worker to stop
worker.request_stop();
worker.join();
return 0;
}