-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (37 loc) · 1.03 KB
/
main.cpp
File metadata and controls
49 lines (37 loc) · 1.03 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
#include <iostream>
#include "sha.h"
#include "md.h"
struct HashTask {
void (*func)(const std::string&);
std::string filePath;
};
void* threadFunc(void* arg) {
HashTask* task = static_cast<HashTask*>(arg);
task->func(task->filePath);
return nullptr;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <file path>" << std::endl;
return 1;
}
std::string filePath = argv[1];
HashTask tasks[5] = {
{ computeFileMD5, filePath },
{ computeFileSHA256, filePath },
{ computeFileKeccak256, filePath },
{ computeFileSHA384, filePath },
{ computeFileSHA512, filePath },
};
pthread_t threads[5];
for (int i = 0; i < 5; ++i) {
if (pthread_create(&threads[i], nullptr, threadFunc, &tasks[i]) != 0) {
std::cerr << "Nie udało się utworzyć wątku " << i << "\n";
}
}
for (int i = 0; i < 5; ++i) {
pthread_join(threads[i], nullptr);
}
return 0;
return 0;
}