-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (43 loc) · 1.3 KB
/
main.cpp
File metadata and controls
55 lines (43 loc) · 1.3 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// main.cpp
// dispatch
//
// Created by Max on 30.06.13.
// Copyright (c) 2013 Max Lunin. All rights reserved.
//
#include "dispatch.h"
#include <assert.h>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
int main(int argc, const char * argv[])
{
auto main_thread_id = std::this_thread::get_id();
for (unsigned task = 0; task < 6; ++task)
for (unsigned priority = 0; priority < 6; ++priority)
{
dispatch::queue(priority).async([=]
{
assert(std::this_thread::get_id() != main_thread_id);
std::string task_string = std::to_string(task);
std::string palceholder(1+priority*5, ' ');
dispatch::queue::main_queue()->async([=]
{
assert(std::this_thread::get_id() == main_thread_id);
std::cout << palceholder << task_string << std::endl;
});
});
}
dispatch::queue(dispatch::QUEUE_PRIORITY::BACKGROUND).async([]
{
std::chrono::milliseconds timespan(1); // or whatever
std::this_thread::sleep_for(timespan);
std::cout << "exit" << std::endl;
dispatch::exit();
});
dispatch::main_loop([]{
std::cout << ".";
});
return 0;
}