回答編集履歴
3
追記
test
CHANGED
@@ -37,3 +37,111 @@
|
|
37
37
|
}
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
[追記] こんなことがやりたいのかな:
|
42
|
+
|
43
|
+
```C++
|
44
|
+
|
45
|
+
#define _CRT_SECURE_NO_WARNINGS
|
46
|
+
|
47
|
+
#include <thread>
|
48
|
+
|
49
|
+
#include <iostream>
|
50
|
+
|
51
|
+
#include <string>
|
52
|
+
|
53
|
+
#include <cstring>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
int ThradProcess1(int argc, char* argv[]) {
|
58
|
+
|
59
|
+
if ( argc < 2 ) return -1;
|
60
|
+
|
61
|
+
for ( int i = 1; i < argc; ++i ) {
|
62
|
+
|
63
|
+
std::cout << (std::string(argv[0]) + " は " + argv[i] + " を画面に描くよ!\n");
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
return 0;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
int ThradProcess2(int argc, char* argv[]) {
|
74
|
+
|
75
|
+
if (argc < 3) return -1;
|
76
|
+
|
77
|
+
std::cout << (std::string(argv[0]) + " は " +
|
78
|
+
|
79
|
+
argv[1] + " の距離情報を " +
|
80
|
+
|
81
|
+
argv[2] + " に書き込むよ\n");
|
82
|
+
|
83
|
+
return 0;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
int make_argv(char* commandline, char* argv[]) {
|
90
|
+
|
91
|
+
int argc = 0;
|
92
|
+
|
93
|
+
for ( char* token = strtok(commandline, " "); token; token = strtok(NULL, " ")) {
|
94
|
+
|
95
|
+
argv[argc++] = token;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
return argc;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
int main() {
|
106
|
+
|
107
|
+
char command1[] = "ThreadProcess1 picture.png";
|
108
|
+
|
109
|
+
char* argv1[8];
|
110
|
+
|
111
|
+
int argc1 = make_argv(command1, argv1);
|
112
|
+
|
113
|
+
std::thread thread1(ThradProcess1, argc1, argv1);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
char command2[] = "ThreadProcess2 objects.png distance.csv";
|
118
|
+
|
119
|
+
char* argv2[8];
|
120
|
+
|
121
|
+
int argc2 = make_argv(command2, argv2);
|
122
|
+
|
123
|
+
std::thread thread2(ThradProcess2, argc2, argv2);
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
thread1.join();
|
128
|
+
|
129
|
+
thread2.join();
|
130
|
+
|
131
|
+
std::cout << "おしごとおしまい\n";
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
実行結果:
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
ThreadProcess1 は picture.png を画面に描くよ!
|
142
|
+
|
143
|
+
ThreadProcess2 は objects.png の距離情報を distance.csv に書き込むよ
|
144
|
+
|
145
|
+
おしごとおしまい
|
146
|
+
|
147
|
+
```
|
2
追記
test
CHANGED
@@ -15,3 +15,25 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
ここで引数食わせてあげなよ。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
おそらくは:
|
22
|
+
|
23
|
+
```C++
|
24
|
+
|
25
|
+
int main(int argc, char* argv[]) {
|
26
|
+
|
27
|
+
std::thread th1(ThradProcess1, argc, argv);
|
28
|
+
|
29
|
+
std::thread th2(ThradProcess2, argc, argv);
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
th1.join();
|
34
|
+
|
35
|
+
th2.join();
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
```
|
1
微修正
test
CHANGED
@@ -14,4 +14,4 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
引数食わせてあげなよ。
|
17
|
+
ここで引数食わせてあげなよ。
|