-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue
104 lines (58 loc) · 1.46 KB
/
queue
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <thread>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
using namespace std;
int a,b,c,d;
//This is the function that will run in parallel
// It will be passed to the thread
void thread_method() {
this_thread::sleep_for(std::chrono::milliseconds(500));
cout << "Function running in thread 1";
a=GetTickCount()%10;
cout<<a;
//std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
void thread_method2() {
std::this_thread::sleep_for(std::chrono::milliseconds(250));
cout << "Function running in thread 2";
b=GetTickCount()%10;
cout<<b;
}
void thread_method3() {
std::this_thread::sleep_for(std::chrono::milliseconds(700));
cout << "Function running in thread 3";
c=GetTickCount()%10;
cout<<c;
}
int main() {
//This statement will launch thread in parallel to main function
thread t(thread_method);
thread t2(thread_method2);
thread t3(thread_method3);
public int queue1[100],queue2[100],queue3[100],queue4[100];
int front=rear=-1;
public enqueue(int q[],int size)
{
for(int i=0;i<size;i++)
{
srand(time(NULL))
q[i]=rand()%10 +1;
}
while(--size>0)
{
if(rear==-1)
{
rear=rear+1;
}
}
}
//std::this_thread::sleep_for(std::chrono::milliseconds(200));
cout << "The main function execution\n";
cout<<GetTickCount()%10;
//This is how we join the new thread with main
//t.join();
getchar();
return 0;
}